滚动多个ListViews for Android

And*_*ess 33 android listview scrollview android-linearlayout

我完全被这个困扰了.我有三个不同的列表需要在屏幕上显示.列表完全可能会延伸到屏幕的下边缘,所以我需要滚动.

我已经尝试过ScrollView和一个LinearLayout孩子一起使用,然后把我ListViewsLinearView所有ListViews锁都用滚动条固定在一个固定的高度上.使用其他类型的布局意味着不滚动.

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

Ric*_*ard 12

touched视图转发到其他视图的触摸事件.您的所有视图也将同步展开/折叠.

   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 list=0; list<items; list++){
                    AbsListView listView =mLayoutWithListViews.getChildAt(list));
                    if(listView != v){
                         listView.onTouchEvent(newEvent);
                    }
                }
            }
            return false;
        }
    };
Run Code Online (Sandbox Code Playgroud)


pup*_*eno 6

我还没有这样做,但我一直在考虑它,因为我可能需要这样做.我可以想到三个选项:只使用一个列表和所有列表的内容.您可以创建一个ListAdapter来执行该操作并插入某种标头.这可能是非常可重用的东西.

另一个想法是列出清单.但这听起来像是在寻找麻烦.

  • 第三种选择是什么?因为我也对这个话题感兴趣,并且我试图用ListView方法做ListViews的问题http://stackoverflow.com/questions/1526831/android-scrollview-layout-problem(尽管我还没有看到你的回答之前).与#android-dev上的人交谈,将ListView放在ListView中比将它们放在ScrollView中更糟糕.(我的结果也是如此.)因为很久以前写的战争后期,你现在已经在列表解决方案中尝试了全部吗? (2认同)

hgl*_*lnt 6

我有一个类似的问题,除了我有两个GridView和一个ListView滚动.我通过手动设置ListViews和GridView的高度来解决它:

    ListAdapter listAdapter = listView.getAdapter();

    int rows = listAdapter.getCount() / columns;
    int height = 60 * rows; // Insert the general cell height plus the dividers.

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = height;
    listView.setLayoutParams(params);
    listView.requestLayout();
Run Code Online (Sandbox Code Playgroud)

希望我能帮助别人.