Fixed: Andorid ExpandableListView issue With CollapsingToolbarLayout
RecyclerView , Listview, Gridview or ExpandableListview doesn't work inside Scrollview when used with CollapsingToolbarLayout.
When you try to scroll the List Its scrolling behaviour doen't work.
To make it work you must override this onMeasure(); of Your ListView or whatever type of List you're using.
@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();
}
You can use NonScrollExpandableListView
you can achieve non-scroll property of any Lisview
or GridView
or ExpandableListView
by overriding following method.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();
}
}
Implementing this in our CollapsingToolbarLayout.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root_coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<android.support.v7.widget.Toolbar
android:id="@+id/budget_app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/gradient"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin" />
<TextView
android:id="@+id/category_count_TV_budget_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/gradient"
android:paddingLeft="@dimen/sixteen_dp"
android:paddingStart="@dimen/sixteen_dp"
android:paddingTop="@dimen/eight_dp"
android:text="Some text"
android:textColor="@color/white"
android:textSize="@dimen/sixteen_sp" />
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.tacktile.contassist.helper.classes.NonScrollExpandableListView
android:id="@+id/expandable_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:focusable="false"
android:groupIndicator="@null"
/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
customise this above xml as per your requirement.
Now this will work with your ExpandableListView. Fixed!!
SRC: https://stackoverflow.com/a/37605908/3863332
This Blog is written in short to solve the problem only. I'm not professional Blogger but like to write for others in the same problem.
Feel free to ask anything.
Thanks
Comments
Post a Comment