how to put text under image view

31,970

Solution 1

If the CompoundDrawable doesn't meet your needs, you may use a RelativeLayout instead of a LinearLayout like this:

    <RelativeLayout
        android:id="@+id/relative"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/logonews" />

        <TextView
            android:id="@+id/textLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/imageLabel"
            android:layout_centerInParent="true"
            android:singleLine="true"
            android:text="Israel News"
            android:textSize="18sp"
            android:textStyle="bold" />
    </RelativeLayout>

Solution 2

Considered using textview with drawable on top? http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableTop

in xml: android:drawableTop

Share:
31,970
Vitaly Menchikovsky
Author by

Vitaly Menchikovsky

By day: worked at Amdocs for 2 years as FE &amp; BE Dev(JAVA,Backbone...), Now working at Gala coral as a FE dev with Backbone. Know also JS,Angular,redux,react, ionic, Java, Bootstrup,auto testing cucumber,firebase. Hobbies: know LR, photo Shop, and professional photography.

Updated on September 15, 2020

Comments

  • Vitaly Menchikovsky
    Vitaly Menchikovsky over 3 years

    I wrote some xml but still cant place the text on the center of the screen as image. I want to put the text after my image. On my xml just trying to put text on the center under the image. my xml is:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffffff"
        android:gravity="fill" >
    
        <ViewFlipper
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/flipper"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:flipInterval="2000" >
    
            <LinearLayout
                android:id="@+id/Linear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:baselineAligned="false"
                android:orientation="vertical" >
    
                <ImageView
                    android:id="@+id/imageLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/logonews" />
    
                <TextView
                    android:id="@+id/textLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageLabel"
                    android:layout_gravity="center"
                    android:singleLine="true"
                    android:text="Israel News"
                    android:textSize="18sp"
                    android:textStyle="bold" />
            </LinearLayout>
        </ViewFlipper>
    
    </RelativeLayout>