I have a layout containing two textViews and one ImageView.
the first text is aligned to the left. The second is also aligned to the left and is below the first text. the image is aligned to the RIGHT! and is aligned to the top of the first text and the bottom of the second text.
I tried to use a RelativeLayout for the job but the Image refuse to align to the right.
Here is my xml
<RelativeLayout
android:id="@+id/NameAndPhoto"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/Names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/FirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/contact_page_name_text_style" >
</TextView>
<TextView
android:id="@+id/LastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/contact_page_name_text_style" >
</TextView>
</LinearLayout>
<ImageView
android:id="@+id/PersonPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/Names"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/Names"
android:layout_toRightOf="@id/Names"
android:contentDescription="@string/contact_page_photo_content_description"
android:padding="3sp"
android:scaleType="fitCenter" >
</ImageView>
</RelativeLayout>
Please advise.
Thanks, Ika.
If you wish to use LinearLayout, use
width="match_parent"and align by settinggravity="right". So you move text in the view that has the width of the parent.As for your placing ImageView in RelativeLayout, you have a contradiction there:
android:layout_alignParentRight="true"andandroid:layout_toRightOf="@id/Names"– two different horizontal placings.Also, you can’t use simultaneously bottom and top placing. And you are using them in Image. Again a contradiction.
And how can you place the Image to the right of the LinearLayout that takes all the width of the root layout? Where could it be placed? Change width of the Names to wrap_content