Aakash
Aakash

Reputation: 65

how to set text on image view using table layout?

i have use android studio and and in XML file i m use the table layout and put image view on table row and i have to set text on image view how is this possible?

my out put is: http://postimg.org/image/czfu60751/

original out put is: http://postimg.org/image/ea19hefpv/

XML code:
<TableRow
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:gravity="center_horizontal">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="390dp"
        android:layout_height="300dp"
        android:background="@drawable/letestnews"
        android:text="@string/letestnews"
        android:textColor="#000"
        android:padding="20dip"
        android:gravity="center" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_weight="1"
        android:text="@string/babaji"
        android:layout_height="fill_parent"
        android:background="@drawable/babaji"
        android:textColor="#000"
        android:padding="20dip"
        android:gravity="center"/>
</TableRow>

<TableRow
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:gravity="center_horizontal">

<ImageView
    android:id="@+id/imageView2"
    android:layout_weight="1"
    android:layout_height="300dp"
    android:layout_width="fill_parent"
    android:background="@drawable/babajispeaks"
    android:text="@string/babajispeaks"
    android:textColor="#ffffff"
    android:gravity="center"/></TableRow>

<TableRow
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:gravity="center_horizontal">
    <ImageView
        android:id="@+id/imageView3"
        android:layout_height="300dp"
        android:background="@drawable/meditation"
        android:text="@string/meditation"
        android:layout_weight="1"
        android:textColor="#ffffff"
        android:padding="20dip"
        android:gravity="center"
        />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_height="300dp"
        android:layout_width="390dp"
        android:background="@drawable/teaching"
        android:text="@string/teaching"
        android:textColor="#ffffff"
        android:padding="20dip"
        android:gravity="center" />
    </TableRow>

Upvotes: 1

Views: 2597

Answers (2)

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

Try this way,hope this will help you to solve your problem.

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Image 1"
                android:layout_margin="5dp"
                android:layout_gravity="bottom"/>

            </FrameLayout>
        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Image 2"
                android:layout_margin="5dp"
                android:layout_gravity="bottom"/>

        </FrameLayout>
        </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Image 3"
                android:layout_margin="5dp"
                android:layout_gravity="bottom"/>

        </FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Image 4"
                android:layout_margin="5dp"
                android:layout_gravity="bottom"/>

        </FrameLayout>
        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Image 5"
                android:layout_margin="5dp"
                android:layout_gravity="bottom"/>

        </FrameLayout>
    </LinearLayout>
</LinearLayout>

Upvotes: 1

naweinberger
naweinberger

Reputation: 429

One option would be to have your table rows contain RelativeLayouts that each contain an ImageView and TextView overlaid.

Consider "..." to be your layout specifications.

For example:

<TableRow ...>

    <RelativeLayout ...>
        <ImageView .../>
        <TextView .../>
    </RelativeLayout>

    <RelativeLayout ...>
        <ImageView .../>
        <TextView .../>
    </RelativeLayout>

    ...

</TableRow>

Upvotes: 2

Related Questions