2016-07-20 6 views
1
 <?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/parentLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=""> 
    <include android:id="@+id/contentLayout" layout="@layout/content_our_story" /> 
</android.support.design.widget.CoordinatorLayout> 

content_our_story.xmlkann nicht dynamisch Layoutparameter für Relative-Layout festgelegt im Inneren Include-Datei zeigt Klasse Guss Ausnahme

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="" 
    android:layout_margin="5dp" 
    tools:showIn="@layout/activity_our_story"> 


</RelativeLayout> 

Einstellung Layout param Code:

contentLayout = (RelativeLayout) findViewById(R.id.contentLayout); 
    RelativeLayout.LayoutParams param=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 
     param.setMargins(0,0,0,0); 
     contentLayout.setLayoutParams(param); 

Wenn ich versuche, LayoutParams einstellen Mit der ID von "contentLayout" wird die Klassenübergabeausnahme angezeigt und erwartet, dass es sich um ein Koordinatorlayout handelt. Es enthält jedoch ein relatives Layout wie oben gezeigt.

+1

CoordinatorLayout.LayoutParams param = new CoordinatorLayout.LayoutParams (CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.MATCH_PARENT); –

Antwort

1

Sie müssen LayoutParams von Eltern Layout-Ansicht verwenden Sie params setzen möchten:

CoordinatorLayout.LayoutParams param=new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.MATCH_PARENT);