2016-07-14 21 views
0

我想動態更改NestedScrollView的高度。但我得到FATAL error。基本上這是一個底部片,我想要在STATE_EXPANDED之前更改高度。無法更改Nestedscrollview的佈局參數動態(android)

我的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

我自己得到了答案。

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);