[英]How to put a framelayout in a layout with buttons?
I've 9 buttons in 3 rows, and I want a FrameLayout
too.我有 3 行 9 个按钮,我也想要一个FrameLayout
。 The purpose of it is that when a user clicks on the menu options and chooses something it has to remove the buttons and open the FrameLayout
.它的目的是当用户单击菜单选项并选择某些内容时,它必须删除按钮并打开FrameLayout
。 What I need help for is the XML for this layout as weird things happen when I try to put a FrameLayout
This is what happens when I try to put a FrameLayout
:我需要帮助的是此布局的 XML,因为当我尝试放置FrameLayout
时会发生奇怪的事情这是我尝试放置FrameLayout
时发生的情况:
And this is how it looks like when I don't have it:这就是我没有它时的样子:
Here is my XML for the layout:这是我的布局 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>
You have the linear layout inside the framelayout.你有内部的FrameLayout线性布局。 It should be a peer not a parent.它应该是同伴而不是父母。
<?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>
Then in your java code:然后在你的java代码中:
viewSwitcher.setDisplayedChild (0);
to show the frame layout and显示框架布局和
viewSwitcher.setDisplayedChild (1);
to show the linearlayout.显示线性布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.