2016-03-19 18 views
0

Ich kann ein Fragment löschen, wenn ich auf eine Schaltfläche klicke, und ich habe 2 andere Fragmente mit der gelöschten, was ich will ist, wenn das erste Fragment gelöscht wird, füllen die beiden anderen den leeren Raum verursacht durch das gelöschte Fragment.Layout des Fragments in Mainactivity ändern

enter image description here

und wenn ich auf eine Schaltfläche klicken, wird sie gelöscht:

enter image description here

aber es ist leerer Raum, möchte ich die beiden Fragmente den leeren Raum

richtig füllen Activity_main_Layout.xml

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

 
    <FrameLayout 
 
     android:layout_width="87dp" 
 
     android:layout_height="match_parent" 
 
     android:layout_gravity="center_vertical" 
 
     android:id="@+id/frml"></FrameLayout> 
 

 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:context="com.example.pack2.t9ahbin.MainActivity" 
 
    android:orientation="vertical" 
 
    android:id="@+id/linear" 
 
    > 
 

 
    <fragment 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:name="com.example.pack2.t9ahbin.FragA" 
 
     android:id="@+id/fragment" 
 
     android:layout_weight="1" 
 
     /> 
 

 
    <fragment 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:name="com.example.pack2.t9ahbin.fragB" 
 
     android:id="@+id/fragment2" 
 
     android:layout_weight="1" 
 
     /> 
 
</LinearLayout> 
 

 
</LinearLayout>

+1

Bearbeiten Sie Ihre Frage entfernen Sie die übergeordnete Aktivität Layout –

Antwort

0

Set Sichtbarkeit = f1 Container gegangen, nachdem Sie es

+0

dank umfassen! nur die Sichtbarkeit des Containers zu setzen, der das Fragment an GONE hält, hat es getan. Ich habe versucht, die dritte Lösung, weil ich etwas über die beiden anderen verstanden habe: 'D –

Verwandte Themen