2012-05-17 51 views
5

Tengo diseño relativo, es decir principal.xml que configuro de la siguiente manera. Pero ahora tengo que poner view1 en view2 con width = 200dp y height = 100dp, por lo que view2 será grande y view1 será pequeño.Cambiar el diseño relativo programáticamente

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> 

Respuesta

27

¿Qué quieres lograr? Si solo desea cambiar el ancho y el alto de:

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

luego llame a invalidate() desde rl luego. –

+0

Gracias, funcionó perfectamente para mí. – user1400285

+0

No ocurre nada cuando llamo a rl.invalidate(). Pero cambiará después de desplazarme por la pantalla. De todos modos para actualizar toda la regla? –

Cuestiones relacionadas