2012-03-28 4 views
0
다음

android에서 조각의 무게 크기를 변경하는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="100" 
    > 

    <fragment 
     android:id="@+id/menuFragment" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="70" 

     class="com.pack.Menufragment" > 
    </fragment> 

    <fragment 
     android:id="@+id/bodyFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="30" 
     class="com.pack.BodyFragment" > 
    </fragment> 

</LinearLayout> 

가 지금은없는 XML에서 자바에서 조각 무게의 크기를 변경하려면 내 조각보기의 XML-레이아웃이며,이를 위해 어쨌든 있나요?

답변

2

필자는 조각을 별도의 LinearLayout에 넣고 그 무게를 변경해야합니다.

처럼 : 자바

에서

<LinearLayout 
    android:id="@+id/layout1" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="70" 

    <fragment 
     android:id="@+id/menuFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 

     class="com.pack.Menufragment" > 
    </fragment> 
</LinearLayout> 
<LinearLayout 
    android:id="@+id/layout2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="30" 
    <fragment 
     android:id="@+id/bodyFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.pack.BodyFragment" > 
    </fragment> 
</LinearLayout> 

LinearLayout layout1 = (LinearLayout) findViewById(R.id.layout1); 
android.widget.LinearLayout.LayoutParams par = layout1.getLayoutParam(); 
par.weight = NEW value; 
+0

나는 이것을했지만, 오류를 보이지는 않지만 크기에 영향을주지는 않습니다. –

1

this related question를 참조하십시오. 각 조각을 FrameLayouts에 포함시킨 다음이 각 프레임 레이아웃의 가중치를 설정하면이 방법을 사용할 수 있습니다.

0

당신은이 스레드에 RelativeLayout의에 대한 수행 방법은 한 번 봐 가지고 할 수 있습니다 : Android - How do I specify weight programmatically for a RelativeLayout? 내가 가정 조각에 대한 레이아웃 PARAMS와 비슷해야을, 그렇게 내가 어떤을 포기하지 않을거야 시도하지 않은 이것이 효과가 있는지 여부에 대한 보장.

관련 문제