`

解决ScrollView中嵌套ListView滚动效果冲突问题

 
阅读更多

在一个界面中既有普通控件(如:image) , 还有 listview 或 gridview , 那么如果记录比较多, 就会超出默认高度,但是无法滚动 .   解决方案如下:

1. 继承listview或gridview , 重写onMeasure方法

2. 使用scrollview包裹自定义的 listview或gridview

 

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class InnerListView extends ListView {

	public InnerListView(Context context) {
		super(context);
	}
	public InnerListView(Context context, AttributeSet attrs, int defStyle) {  
        super(context, attrs, defStyle);  
	}  
	public InnerListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
	        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
	                        MeasureSpec.AT_MOST);  
	        super.onMeasure(widthMeasureSpec, expandSpec);  
	}  
}

 

<LinearLayout
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:background="@color/white">
	    	<ScrollView  
		    android:layout_width="fill_parent"  
		    android:layout_height="fill_parent"  
		    android:scrollbars="vertical"  
		    android:fadingEdge="vertical">
				<org.photo.InnerListView
				    android:id="@+id/review_msg"
				    android:layout_width="fill_parent"
				    android:layout_height="fill_parent"
				    android:cacheColorHint="@android:color/transparent"
				    android:divider="@color/light_gray"
				    android:dividerHeight="1px"
				    android:drawSelectorOnTop="false" >
				</org.photo.InnerListView>
		</ScrollView>
	</LinearLayout>

 

参考:

http://trinea.iteye.com/blog/1084707

 

http://my.oschina.net/xsjayz/blog/95113

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics