2012-05-17 43 views
5

Bố cục tương đối, nghĩa là main.xml mà tôi đặt như sau. Nhưng bây giờ tôi đã đặt view1 trên view2 với width = 200dp và height = 100dp, do đó view2 sẽ lớn và view1 sẽ là một nhỏ trên đó.Thay đổi bố cục tương đối theo chương trình

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> 

Trả lời

27

Bạn muốn đạt được điều gì? Nếu bạn chỉ muốn thay đổi chiều rộng và chiều cao hơn:

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

sau đó gọi invalidate() từ rl sau đó. –

+0

Cảm ơn, Nó hoàn toàn phù hợp với tôi. – user1400285

+0

Không có gì xảy ra khi tôi gọi rl.invalidate(). Nhưng nó sẽ thay đổi sau khi tôi cuộn màn hình. Dù sao để làm mới toàn bộ screed? –

Các vấn đề liên quan