Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - NestedScrollView which contains ExpandableListView doesn't scroll when expanded

Tags:

I have an ExpandableListView inside a NestedScrollView (yes I know, it is not good to have a scrolling view inside another scrolling view but I don't know what else to do, please do tell me if anybody knows a better approach).

The size of the content in NestedScrollView is still within the screen so it won't scroll, but when ExpandableListView is expanded, the content will leak outside the screen but the NestedScrollView still won't scroll.. Why is this so?

Here's my NestedScrollView layout :

<NestedScrollView>     <LinearLayout>         <LinearLayout></LinearLayout>         ... // About 3 of the LinearLayouts         <ExpandableListView/>     </LinearLayout> </NestedScrollView> 
like image 823
Kevin Murvie Avatar asked Jun 03 '16 03:06

Kevin Murvie


People also ask

How do I stop NestedScrollView scrolling?

setnestedscrollingenabled set it to false.

What is nested scrolling Android?

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. It is enabled by default. NestedScrollView is used when there is a need for a scrolling view inside another scrolling view.

What is ScrollView and listview in android?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.


2 Answers

You can use NonScrollExpandableListView you can achieve non-scroll property of any Lisview or GridView or ExpandableListView by overriding following method.

@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {     int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(             Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);     super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);     ViewGroup.LayoutParams params = getLayoutParams();     params.height = getMeasuredHeight(); }  

So for using NonScrollExpandableListView you need to make one custom class.

public class NonScrollExpandableListView extends ExpandableListView {      public NonScrollExpandableListView(Context context) {         super(context);     }      public NonScrollExpandableListView(Context context, AttributeSet attrs) {         super(context, attrs);     }      public NonScrollExpandableListView(Context context, AttributeSet attrs, int defStyle) {         super(context, attrs, defStyle);     }      @Override     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {         int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(                 Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);         super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);         ViewGroup.LayoutParams params = getLayoutParams();         params.height = getMeasuredHeight();     } } 

And use it like.

<com.example.extraclasses.NonScrollExpandableListView       android:layout_width="match_parent"     android:layout_height="wrap_content" />  

Happy coding.

like image 90
V-rund Puro-hit Avatar answered Oct 19 '22 02:10

V-rund Puro-hit


Add android:nestedScrollingEnabled="true" to your ExpandalbleListView layout.

like image 20
Paweł B Avatar answered Oct 19 '22 02:10

Paweł B