大佬教程收集整理的这篇文章主要介绍了android – ScrollView使自定义布局不可见,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<ScrollView xmlns:android="http://scheR_577_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_577_11845@as.android.com/tools" android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <com.example.test.CustomLayout android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="wrap_content" > </com.example.test.CustomLayout> </ScrollView>
我的观点组:
protected void onMeasure(int widthMeasureSpec,int heightMeasureSpeC){ super.onMeasure(widthMeasureSpec,heightMeasureSpec); /* do something and call for each child View v = getChildAt(i); v.measure(wspec,hspec); */ setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(),widthMeasureSpeC),getDefaultSize(getSuggestedMinimumHeight(),heightMeasureSpeC)); } protected void onLayout(Boolean changed,int l,int t,int r,int b) { // TODO Auto-generated method stub //do something and call layout on every child }
更新:
我的CustomLayout类
public class CustomLayout extends ViewGroup{ /*My params*/ public CustomLayout(Context context) { super(context); // TODO Auto-generated constructor stub } public CustomLayout(Context context,AttributeSet attrs) { super(context,attrs); } public CustomLayout(Context context,AttributeSet attrs,int defStylE) { super(context,attrs,defStylE); } @Override protected void onLayout(Boolean changed,int b) { // TODO Auto-generated method stub //do something and call layout on every child } protected void onMeasure(int widthMeasureSpec,heightMeasureSpec); /* do something and call for each child View v = getChildAt(i); v.measure(wspec,hspec); */ setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(),heightMeasureSpeC)); } }
更新2:
抱歉,我做了一些其他的尝试,如果我在onMeasure方法的滚动视图中有viewgroup,我得到heightMeasureSpec = 0,然后如果我把viewgroup放在任何其他布局,我得到一个整数.也许这会有所帮助?
int heightMeasured = 0; /*for each child get height and heightMeasured += childHeight;*/ //If I am in a scrollview i got heightmeasurespec == 0,so if(heightMeasureSpec == 0){ heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightMeasured,MeasureSpec.AT_MOST); } setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(),getDefaultSize(this.getSuggestedMinimumHeight(),heightMeasureSpeC));
现在对我来说它有效.
以上是大佬教程为你收集整理的android – ScrollView使自定义布局不可见全部内容,希望文章能够帮你解决android – ScrollView使自定义布局不可见所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。