Android 如何在带有按钮的布局中放置框架布局?
我有3行9个按钮,我还想要一个Android 如何在带有按钮的布局中放置框架布局?,android,xml,android-layout,android-framelayout,Android,Xml,Android Layout,Android Framelayout,我有3行9个按钮,我还想要一个FrameLayout。其目的是,当用户单击菜单选项并选择某个内容时,必须删除按钮并打开框架布局。我需要帮助的是这个布局的XML,因为当我尝试放置FrameLayout 这就是我尝试放置框架布局时发生的情况: 这就是我没有它时的样子: 以下是我的布局XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com
FrameLayout
。其目的是,当用户单击菜单选项并选择某个内容时,必须删除按钮并打开框架布局
。我需要帮助的是这个布局的XML,因为当我尝试放置FrameLayout
这就是我尝试放置框架布局时发生的情况:
这就是我没有它时的样子:
以下是我的布局XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#32c6a6"
android:weightSum="3">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linRow1"
android:layout_weight="1"
android:weightSum="3">
<Button
android:text="13 egenskaber"
android:id="@+id/G_Egenskaber"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Profeternes egenskaber"
android:id="@+id/P_egenskaber"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Bøntider"
android:id="@+id/Boentider"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linRow2"
android:layout_weight="1"
android:weightSum="3">
<Button
style="?android:attr/buttonStyleSmall"
android:text="Wudu"
android:id="@+id/Wudu"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bluebotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Wudu's betingelser"
android:id="@+id/Wudu_B"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bluebotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
style="?android:attr/buttonStyleSmall"
android:text="Wudu's afbrydelser"
android:id="@+id/Wudu_A"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bluebotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linRow3"
android:layout_weight="1"
android:weightSum="3">
<Button
android:text="Bønnens søjler"
android:id="@+id/Boen_S"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yellowbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Bønnens betingelser"
android:id="@+id/Boen_B"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yellowbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Bønnens afbrydelser"
android:id="@+id/Boen_A"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yellowbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
在框架布局内部有线性布局。它应该是同龄人而不是父母
<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switcher"
android:layout_weight="0"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/buttons"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#32c6a6">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linRow1"
android:layout_weight="1"
android:weightSum="3">
<Button
android:text="13 egenskaber"
android:id="@+id/G_Egenskaber"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Profeternes egenskaber"
android:id="@+id/P_egenskaber"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Bøntider"
android:id="@+id/Boentider"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linRow2"
android:layout_weight="1"
android:weightSum="3">
<Button
style="?android:attr/buttonStyleSmall"
android:text="Wudu"
android:id="@+id/Wudu"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bluebotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Wudu's betingelser"
android:id="@+id/Wudu_B"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bluebotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
style="?android:attr/buttonStyleSmall"
android:text="Wudu's afbrydelser"
android:id="@+id/Wudu_A"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bluebotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linRow3"
android:layout_weight="1"
android:weightSum="3">
<Button
android:text="Bønnens søjler"
android:id="@+id/Boen_S"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yellowbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Bønnens betingelser"
android:id="@+id/Boen_B"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yellowbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
<Button
android:text="Bønnens afbrydelser"
android:id="@+id/Boen_A"
android:textSize="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/yellowbotton"
android:layout_weight="1"
android:textColor="#ffffff"/>
</LinearLayout>
</LinearLayout>
</ViewSwitcher>
显示框架布局和
viewSwitcher.setDisplayedChild (1);
显示线性布局。您可以创建两个布局xml,一个带有按钮,另一个带有框架布局,然后可以使用充气工具加载。现在,我只得到红色按钮,而不是yellow@dadadudu更改了答案,因为我犯了一个错误,并为您想出了更好的解决方案。GridLayout将是另一种选择嗯,有件事我不太明白。为什么要将可见性设置为“已消失”?我希望他们在那里,我想只有在他们点击一个按钮后,框架布局才会显示出来。使用视图切换器,您不需要设置可见性,只需告诉它要显示哪个子对象-0或1。
viewSwitcher.setDisplayedChild (1);