Jorge181
Jorge181

Reputation: 307

TextView below ImageView

I can't place the label where i want. I will show a picture.

enter image description here

I have the following code:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textViewNombreVideo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageViewLogo"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/imageViewLogo"
        android:lines="2"
        android:scrollHorizontally="false"
        android:singleLine="false"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearance"
        android:textColor="@android:color/white"
        android:textColorLink="@android:color/white"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/imageViewLogo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/textViewNombreVideo"
        android:layout_centerHorizontal="true"
        android:layout_margin="4dp"
        android:adjustViewBounds="true" />

</RelativeLayout>

The picture fit the heigh of the imageview, that's ok, and i want to place the textview with the same left of the picture.

Is it possible to do that?

Upvotes: 4

Views: 15224

Answers (4)

user2118554
user2118554

Reputation:

use Button instead of ImageView and TextView as..

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button Text"
        android:drawableTop="@drawable/youriconname"

        />

try this may help you..

Upvotes: 0

Mr.Sandy
Mr.Sandy

Reputation: 4349

Try this code.

<?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="match_parent"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textViewNombreVideo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_alignLeft="@+id/imageViewLogo"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/imageViewLogo"
        android:lines="2"
        android:scrollHorizontally="false"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearance"
        android:textColor="@android:color/black"
        android:textColorLink="@android:color/white"
        android:textStyle="bold"
        android:layout_marginBottom="10dp" />

    <ImageView
        android:id="@+id/imageViewLogo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/textViewNombreVideo"
        android:layout_centerHorizontal="true"
        android:layout_margin="4dp"
        android:src="@drawable/ic_launcher"
        android:adjustViewBounds="true"
     />

</RelativeLayout>

below UI design fron this code. as per your requirement.

enter image description here

Upvotes: 4

Pragnani
Pragnani

Reputation: 20155

Try this

No need to Take a RelativeLayout to adjust, you can simply achieve that with TextView bye simply setting android:drawableTop attribue of the TextView

Example: android:drawableTop="@drawble/yourimage"

       <TextView
        android:id="@+id/textView"
         android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawble/yourimage"
        android:text="Hello"
       />

Upvotes: 0

zennon
zennon

Reputation: 1090

I think you have to add the Gravity option to your TextView:

android:gravity ="center"

Upvotes: 0

Related Questions