ScrollView嵌套Listview或GridView

来源:互联网 发布:淘宝天下小二是什么 编辑:程序博客网 时间:2024/05/16 19:22

项目中遇到ScrollView需要嵌套Listview,但是Listview只显示一行数据,以下是解决的方法,需要自定义类继承Listview,(GridView类似)

package cn.com.demo.view;public class CustomListView extends ListView{    public CustomListView(Context context) {        super(context);    }    public CustomListView(Context context, AttributeSet attrs) {        super(context, attrs);    }    /**     * 计算ListView显示的高度     */    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);        super.onMeasure(widthMeasureSpec, expandSpec);    }}

然后需要吧Listview的布局改成自定义的Listview即可

 <cn.com.demo.view.CustomListView            android:id="@+id/list_package"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:divider="@color/list_line"            android:dividerHeight="1dp" />
0 0
原创粉丝点击