在一个界面中既有普通控件(如: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
相关推荐
用于解决scrollview组件嵌套listview组件时候 两者之间的冲突问题
解决ScrollView中嵌套ListView的冲突示例,重写了一个listView,放到ScrollView中,解决了滚动条冲突的问题。
Android中自定义ListView,解决scrollview嵌套listview 滑动事件冲突,是非常常见的问题,我写了一个例子和大家交流学习
解决Scrollview嵌套listview下拉刷新的一些问题
解决ScrollView中嵌套ListView不显示问题
ScrollView中嵌套listview 解决滑动冲突问题
ScrollView中嵌套ListView的例子和解决方案
Scrollview中嵌套listview,listview中再嵌套listview代码示例工程
android 解决ScrollView和listView嵌套冲突问题(保证在ScrollView中滑动listView只响应listView的滑动)
解决ScrollView ListView 滚动条冲突 ,其它带滚动条的控件一样适用 ,主要是固定内层控件的高度 达到可滑动的效果
ScrollView中嵌套ListView,还可以嵌套多个listview 解决无法共存问题。放到项目中可以直接用
很多朋友因项目需求问题需要在ScrollView中嵌套使用ListView或ScrollView 但是彼此的滑动事件会发生冲突,网上大多数都是计算ListView的高度来解决这个问题,但个人亲手尝试 结果ListView的Item要是过多的话ListView...
ScrollView嵌套ListView滑动冲突的解决方案
ScrollView,嵌套ListView,ListView并同时嵌套GridView
利用事件分发机制解决解决ScrollView嵌套ListView使用
解决ScrollView里面嵌套ListVIew引起的高度和滚动问题.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
ScrollView嵌套ListView,当ListView的顶部到达屏幕顶部时,listView才具有滑动能力,当listView滑动到两端时,会触发ScrollView滑动
Android ScrollView嵌套ListView嵌套GridView的上下拉以及加载更多
当ScrollView中嵌套ListView或者GrideView时,listView和GrideView不能完全显示的时候
Scrollview中嵌套ViewPager和ListView常出现的问题: ViewPager如果在Scrollview中使用,并且宽高指定为match_parent或者wrap_content则不会显示内容,但是如果将高度指定为200dp,则ViewPager则会将内容显示到屏幕...