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>
setnestedscrollingenabled set it to false.
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.
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.
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.
Add android:nestedScrollingEnabled="true"
to your ExpandalbleListView layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With