我想动态更改NestedScrollView
的高度。但我得到了FATAL error
。基本上这是一个底片,我想在STATE_EXPANDED
之前更改高度。
我的Java代码:
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);
我的布局是:
<?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
有没有人有建议?
答案 0 :(得分:0)
我自己得到了答案。
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);