解决Scollview和ListView冲突的问题

来源:互联网 发布:飞扬软件托运开单界面 编辑:程序博客网 时间:2024/04/28 18:06

想必大家总会遇到 屏幕当中同事存在 Scollview和ListView 同时存在的情况 ,因为两者手势冲突,所以会造成现实的不正常。其实只要将ListView的高度动态计算出来便可以解决问题。提供一个自定义ListView。


使用这个自定义ListView 可以使之在Scollview中撑开


package com.baojia.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;
/**
* 计算高度
* @author Administrator
*
*/
public class MyListView extends ListView{

     public MyListView(Context context, AttributeSet attrs) {
          super(context, attrs);
     }

     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                 MeasureSpec.AT_MOST);
         super.onMeasure(widthMeasureSpec, expandSpec);
     } 
}

调用方法 就合一般的ListView 一样  在XML中配制

 <com.baojia.view.MyListView
            android:id="@+id/lv"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/white">
</com.baojia.view.MyListView>


把它当做一个常用控件收藏吧大笑
1 0
原创粉丝点击