2012-05-17 13 views
5

私は相対レイアウト、すなわちmain.xmlを以下のように設定しました。しかし今、私はview2に幅= 200dpと高さ= 100dpとview2を入れなければなりません。そうすれば、view2は大きなものになり、view1は小さなものになります。相対的なレイアウトをプログラム的に変更する

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> 

答えて

27

は何を達成したいですか?幅と高さを変更する場合は、

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

を入力し、その後にrlからinvalidate()を呼び出します。 –

+0

ありがとう、それは私のために完璧に働いた。 – user1400285

+0

rl.invalidate()を呼び出すと何も起こりません。しかし、私は画面をスクロールした後に変更されます。とにかくスクリード全体をリフレッシュするには? –

関連する問題