2012-05-17 22 views
5

Ich habe relative Layout, d. H. main.xml, die ich wie folgt festgelegt. Aber jetzt muss ich View1 auf View2 mit width = 200dp und height = 100dp setzen, so dass View2 groß sein wird und view1 klein sein wird.Ändern der relativen Layout programmgesteuert

public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
     } 

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout 
    android:id="@+id/MainPanel" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/panel_bottom" 
    android:layout_gravity="center_horizontal" > 

    <com.proj.demo.view1 
     android:id="@+id/sheet" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignWithParentIfMissing="true" 
     android:layout_centerInParent="true" 
     android:layout_toLeftOf="@+id/panel_quick_buttons" 
     /> 

    <com.proj.demo.view2 
     android:id="@+id/sheet2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignWithParentIfMissing="true" 
     android:layout_centerInParent="true" 
     android:layout_toLeftOf="@+id/panel_quick_buttons" 
     /> 

</RelativeLayout> 
</RelativeLayout> 

Antwort

27

Was wollen Sie erreichen? Wenn Sie nur Breite und Höhe ändern möchten:

RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourId); 
    rl.getLayoutParams().height = 100; 
    rl.getLayoutParams().width = 100; 
+0

dann rufen Sie anschließend invalidate() von rl. –

+0

Danke, es hat perfekt für mich gearbeitet. – user1400285

+0

Nichts geschieht, wenn ich rl.invalidate() aufruft. Aber es wird sich ändern, wenn ich den Bildschirm scrolle. Jedenfalls um den ganzen Estrich zu erfrischen? –

Verwandte Themen