android - 滚动多个 ListViews for Android

标签 android listview scrollview android-linearlayout

我完全被这个难住了。我有三个不同的列表需要显示在屏幕上。列表完全有可能超出屏幕的底部边缘,因此我需要滚动。

我试过将 ScrollViewLinearLayout 子项一起使用,并将我的 ListViews 放入 LinearView ,但所有 ListViews 都锁定到带有滚动条的固定高度。使用其他类型的布局意味着无需滚动。

有没有人有任何建议,或者我是否需要以编程方式将列表项添加到某些布局并希望最好?

最佳答案

将触摸事件从 touched View 转发到其他 View 。您的所有 View 也将同步展开/折叠。

OnTouchListener mOnTouch = new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {            
        MotionEvent newEvent = MotionEvent.obtain(event);

        switch(event.getAction()) {  
            case MotionEvent.ACTION_MOVE:
                if(mTouched == null) {
                    mTouched = v;
                }
                mMovingFlag = true;
                break;
            case MotionEvent.ACTION_UP:
                if(mMovingFlag==false) {
                    newEvent.setAction(MotionEvent.ACTION_CANCEL);
                }
                mMovingFlag = false;
                break;
            default:
                mMovingFlag = false;
                if(mTouched != null && mTouched.equals(v)) {
                    mTouched = null;
                }
                break;
        }

        if(mTouched == null || mTouched.equals(v)) {
            int items = mLayoutWithListViews.getChildCount();
            for(int i = 0; i < items; i++) {
                AbsListView listView = mLayoutWithListViews.getChildAt(i));
                if(listView != v) {
                    listView.onTouchEvent(newEvent);
                }
            }
        }

        return false;
    }
};

关于android - 滚动多个 ListViews for Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6981139/

相关文章:

android - 如何使用加速度计值刷新网页

java - 单击选项 webview 一次又一次重新加载后

Android 刷新 ListView sections-overlay 在 4.4 中不起作用

android - 由于 ScrollView,ListView 表现得很奇怪?

android - 如何判断一个 NestedScrollView 是否滚动到最后并处于空闲状态?

Android Studio 3.5.2 离线设置错误 : app@debug/compileClasspath

Android ListView 滚动到顶部时自动加载更多数据

java - 扫描 ListView 中的复选框的方法

android - 选项卡式 Activity 中的 ScrollView 向下跳转

android - appcompat 模块错误