ListView nested scrolling on API<21

后端 未结 3 2306
长情又很酷
长情又很酷 2020-12-06 18:00

Title is clear. I\'m having this layout:

_________________
|_______________| <- Toolbar    
|___|___|___|___| <- Tablayout
|               |
|                  


        
3条回答
  •  情书的邮戳
    2020-12-06 18:59

    I'm actually a Xamarin developer so I can't test if this works in this particular case, but I found an answer which helped me in Xamarin, so I'm gonna share it:

    I found a solution that works excellently and can scroll the ListView without problems:

    ListView lv = (ListView)findViewById(R.id.myListView);  // your
    listview inside scrollview lv.setOnTouchListener(new
    ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;
    
            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
    
            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });
    

    What this does is disable the TouchEvents on the ScrollView and make the ListView intercept them. It is simple and works all the time.

    If this won't work, please tell me so I can delete this answer. But maybe it helps anyone since I also found this question and it seems to have no solution.

提交回复
热议问题