简体   繁体   中英

How to put a framelayout in a layout with buttons?

I've 9 buttons in 3 rows, and I want a FrameLayout too. 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 . 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 : 在此处输入图片说明

And this is how it looks like when I don't have it:

在此处输入图片说明

Here is my XML for the layout:

<?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. 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:

viewSwitcher.setDisplayedChild (0);

to show the frame layout and

viewSwitcher.setDisplayedChild (1);

to show the linearlayout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM