2012-03-28 19 views
0

Hier ist das XML-Layout meiner Fragment AnsichtWie ändere ich die Größe eines Fragments in 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> 

Jetzt will ich von der Java von XML nicht die Fragmente Gewichtsgröße ändern, ist es dies trotzdem zu tun?

Antwort

2

Ich sollte die Fragmente in eine separate LinearLayout legen und dieses Gewicht ändern.

Like:

<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> 

In Java

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

Ich tat dies, aber es zeigt keinen Fehler, aber auch nicht in der Größe Wirkung –

1

Bitte beachten Sie this related question. Sie können dies verwenden, wenn Sie jedes Ihrer Fragmente in FrameLayouts einschließen und dann die Gewichte für jedes dieser Rahmenlayouts festlegen.

Verwandte Themen