Unknown
Unknown

Reputation: 11

how to align a textview to the right of imageview

I'm a beginner in android development and this is my code (it's relative layout)

<ImageView
    android:id="@+id/logo1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/telephone1"
    android:layout_marginTop="10dp"
    android:layout_below="@id/text4"/>

<TextView
    android:id="@+id/text5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="00966-13-8420444"
    android:fontFamily="sans-serif"
    android:textSize="20sp"
    android:layout_toRightOf="@id/logo1"
    />

I thought android:layout_toRightOf="@id/logo1 is enough and the text was on the right of the image (aligned correctly) but it appears on the top of device (the place of image on the bottom but not on bottom edge), what line of code I should add?

sorry for English. thank you

Upvotes: 1

Views: 2725

Answers (4)

Rajeev Kumar
Rajeev Kumar

Reputation: 59

If I have understood your questions clearly, You want to display image and textview in a single row. Also, Your textview is right side of imageView. If it is so. Please copy/paste below. It should work

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

    <ImageView
        android:id="@+id/logo1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/ic_launcher"/>

    <TextView
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:fontFamily="sans-serif"
        android:text="00966-13-8420444"
        android:textSize="20sp"
        />
</LinearLayout>

Upvotes: 1

Kasun Siyambalapitiya
Kasun Siyambalapitiya

Reputation: 4403

try this

 <ImageView
        android:id="@+id/logo1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/telephone1"
        android:layout_marginTop="10dp"
        android:layout_below="@id/text4"
        android:layout_alignParentLeft="true"/>

    <TextView
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="00966-13-8420444"
        android:fontFamily="sans-serif"
        android:textSize="20sp"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/logo1"

/>

Upvotes: 0

Siddhesh Dighe
Siddhesh Dighe

Reputation: 2954

You can make a Layout Structure like this and then Move around the LinearLayout wherever you like using android:gravity

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="Horizontal">

<ImageView
    android:id="@+id/logo1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/telephone1"
    android:layout_marginTop="10dp"/>

<TextView
    android:id="@+id/text5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="00966-13-8420444"
    android:fontFamily="sans-serif"
    android:textSize="20sp"
    />

</LinearLayout>

Upvotes: 0

leonz
leonz

Reputation: 1127

If I understood your question correctly, you want your text outside the picture, but aligned to its center, try this:

<ImageView
    android:id="@+id/logo1"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/telephone1"
    android:layout_marginTop="10dp"
    android:layout_below="@id/text4"/>

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

    <TextView
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="00966-13-8420444"
        android:fontFamily="sans-serif"
        android:textSize="20sp"
        android:layout_toRightOf="@id/logo1"/>
</LinearLayout>

Upvotes: 1

Related Questions