改变主要活动中片段的布局

时间:2016-03-19 16:07:22

标签: android

当我点击一个按钮时,我可以删除一个片段,我有2个其他片段和删除的片段,我想要的是当第一个片段被删除时,另外两个片段填充由删除片段引起的空白空间。

enter image description here

当我点击一个按钮时,它被删除:

enter image description here

但是有空的空间,我希望这两个片段能够正确填充空白区域

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 个答案:

答案 0 :(得分:0)

设置visibility =删除后移至f1容器