androidxmlandroid-layoutandroid-linearlayout

android:layout_below= Does Not Set TextViews Below ImageButtons in LinearLayout


I'm not sure why but in my linearlayout android:layout_below= Does Not Set TextViews Below ImageButtons.

I know I've overlooked something but I'm not sure exactly what that might be.

enter image description here

Any suggestions are appreciated.

  <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:weightSum="1" >

            <View
                android:id="@+id/view1"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0.3" />

            <ImageButton
                android:id="@+id/photos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/photos" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/photos"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageButton
                android:id="@+id/audio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/audio" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/audio"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageButton
                android:id="@+id/written"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/written" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/written"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <ImageButton
                android:id="@+id/video"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.1"
                android:src="@drawable/video" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/video"
                android:layout_marginTop="17dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <View
                android:id="@+id/view1"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0.3" />
        </LinearLayout>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="800dp"
            android:layout_height="100dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="48dp"
            android:src="@drawable/icon_e" />

    </RelativeLayout>

Solution

  • Try this..

    android:layout_below is only for RelativeLayout not for LinearLayout

    <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true" >
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical" >
    
                <ImageButton
                    android:id="@+id/photos"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:src="@drawable/photos" />
    
                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="17dp"
                    android:gravity="center"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical" >
    
                <ImageButton
                    android:id="@+id/audio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:src="@drawable/audio" />
    
                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="17dp"
                    android:gravity="center"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical" >
    
                <ImageButton
                    android:id="@+id/written"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:src="@drawable/written" />
    
                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="17dp"
                    android:gravity="center"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical" >
    
                <ImageButton
                    android:id="@+id/video"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:src="@drawable/video" />
    
                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="17dp"
                    android:gravity="center"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>
        </LinearLayout>
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="800dp"
            android:layout_height="100dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="48dp"
            android:src="@drawable/icon_e" />
    
    </RelativeLayout>