sjain
sjain

Reputation: 23344

Displaying framelayout one above another

I have a framelayout with id listLayout that contains the button. I want it to be just above the other framelayout with id news_fragment but it is coming besides this.

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/listLayout"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/lists"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/btn_black_xml"           
            android:padding="8dp"
            android:text="List"
            android:textColor="#ffffff"
            android:textSize="20dp" />

        </FrameLayout>


    <FrameLayout
              android:id="@+id/news_fragment"
              android:layout_weight="2"
              android:layout_width="0dp"              
              android:layout_height="match_parent">



        </FrameLayout>

    <FrameLayout
              android:id="@+id/channel_fragment"
              android:layout_weight="3"
              android:layout_width="0dp"
              android:layout_height="match_parent" />

</LinearLayout>

Upvotes: 2

Views: 8878

Answers (3)

Guian
Guian

Reputation: 4689

You LinearLayout is horizontal, that why child views are shown besides each other. try to put it vertical instead :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"> 
...

I hope I understand well you question.

also be aware that you should simplify your layout : having one single view inside some layouts is useless and resource consuming :

in other word :

<FrameLayout
   android:id="@+id/listLayout"
   android:layout_weight="1"
   android:layout_width="0dp"
   android:layout_height="wrap_content">

<Button
    android:id="@+id/lists"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/btn_black_xml"           
    android:padding="8dp"
    android:text="List"
    android:textColor="#ffffff"
    android:textSize="20dp" />

</FrameLayout>

is bad, the FrameLayout is useless.

Upvotes: 2

Guilherme Gregores
Guilherme Gregores

Reputation: 1048

Take a look if it is what are looking for:

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

    <FrameLayout
        android:id="@+id/listLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/lists"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="8dp"
            android:text="List"
            android:textColor="#ffffff"
            android:textSize="20dp" />
    </FrameLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent" >

        <FrameLayout
            android:id="@+id/news_fragment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >
        </FrameLayout>

        <FrameLayout
            android:id="@+id/channel_fragment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >
        </FrameLayout>
    </LinearLayout>

</LinearLayout>

Upvotes: 0

Dim
Dim

Reputation: 4807

Put them both in Linearlayout vertical like so

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/listLayout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <Button
                android:id="@+id/lists"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/btn_black_xml"
                android:padding="8dp"
                android:text="List"
                android:textColor="#ffffff"
                android:textSize="20dp" />
        </FrameLayout>

        <FrameLayout
            android:id="@+id/news_fragment"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2" >
        </FrameLayout>

    </LinearLayout>

    <FrameLayout
              android:id="@+id/channel_fragment"
              android:layout_weight="3"
              android:layout_width="0dp"
              android:layout_height="match_parent" />

</LinearLayout>

Upvotes: 0

Related Questions