Sagar Nayak Sagar Nayak - 4 months ago 63
Android Question

Can't change layout params of Nestedscrollview Dynamically (android)

I want to change the height of a

NestedScrollView
dynamically. but i am getting
FATAL error
. basically this is a bottomsheet, and i want to change the height before it is in
STATE_EXPANDED
.

My Java Code :

bottomsheet_nestedscrollview = (NestedScrollView) findViewById(R.id.bottom_sheet_landing_screen);
NestedScrollView.LayoutParams params = (NestedScrollView.LayoutParams) bottomsheet_nestedscrollview.getLayoutParams();
params.height = bottom_relativeLayout.getHeight();
bottomsheet_nestedscrollview.setLayoutParams(params);


My layout is :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.csm.hptcp.hptcpmobileapp.Landing_Screen">

<include layout="@layout/content_landing__screen" />

<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet_landing_screen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_light"
android:clipToPadding="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

<include layout="@layout/landing_screen_bottomsheet" />

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/bottom_sheet_landing_screen"
app:layout_anchorGravity="top|center" />

</android.support.design.widget.CoordinatorLayout>


Logcat :

FATAL EXCEPTION: main
Process: com.csm.hptcp.hptcpmobileapp, PID: 16854
java.lang.ClassCastException: android.support.design.widget.CoordinatorLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams


Do anyone have a suggestion ?

Answer

I have got the answer myself.

    bottomsheet_nestedscrollview = (NestedScrollView) findViewById(R.id.bottom_sheet_landing_screen);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) bottomsheet_nestedscrollview.getLayoutParams();
    params.height = bottom_relativeLayout.getHeight();
    bottomsheet_nestedscrollview.setLayoutParams(params);