两个listview镶嵌ScrollView无法同时滑动问题

本文介绍了一种在Android应用中实现两个列表视图同步滚动的方法。通过自定义XWListView类并调整其测量方式,结合ScrollView和LinearLayout布局,使得两个列表在滑动到底部时能够同步滚动。

最近在项目中需要在页面中同时显示两个列表,而且在滑动顶部listview到最后一个item的时候整个页面跟着同时滑动,选择了listview,发现无法同时滑动,显示也出现了问题。

解决此问题的方法有很多种,我的解决如下

很简单,重写listview就ok了:

XWListView类:


public class XWListView extends ListView {

    public XWListView(Context context) {
        super(context);
    }

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

    public XWListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

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

}

布局文件:


 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/activity_upload_queue_actionbar"
        android:layout_marginBottom="55dp"
        android:fillViewport="true">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
      
                <cn.longmaster.hospital.doctor.ui.consult.XWListView
                    android:id="@+id/activity_upload_queue_upload_result_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:divider="@null"
                    android:scrollbars="none" />


                <cn.longmaster.hospital.doctor.ui.consult.XWListView
                    android:id="@+id/activity_upload_queue_list_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="5dp"
                    android:divider="@null"
                    android:scrollbars="none" />        
          
        </LinearLayout>
    </ScrollView>

activity类中还跟的listview一样的使用。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值