How to make android listview scrollable?

后端 未结 9 1387
悲&欢浪女
悲&欢浪女 2021-01-03 19:12

I have two listviews, but they don\'t scroll. How do I correct this?

Here is my layout.xml

 

        
9条回答
  •  情话喂你
    2021-01-03 19:51

    Putting ListView inside a ScrollView is never inspired. But if you want your posted XML-like behavior, there're 3 options to me:

    1. Remove ScrollView: Removing your ScrollView, you may give the ListViews some specific size with respect to the total layout (either specific dp or layout_weight).

    2. Replace ListViews with LinearLayouts: You may add the list-items by iterating through the item-list and add each item-view to the respective LinearLayout by inflating the view & setting the respective data (string, image etc.)

    3. If you really need to put your ListViews inside the ScrollView, you must make your ListViews non-scrollable (Which is practically the same as the solution 2 above, but with ListView codes), otherwise the layout won't function as you expect.
      To make a ListView non-scrollable, you may read this SO post, where the precise solution to me is like the one below:

    listView.setOnTouchListener(new OnTouchListener() {
      public boolean onTouch(View v, MotionEvent event) {
        return (event.getAction() == MotionEvent.ACTION_MOVE);
      }
    });

提交回复
热议问题