Reputation: 1314
I want to place an image to the right of the view. For that I am tyring to use something like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
...some other elements
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/imageIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/image_icon" >
</ImageView>
</LinearLayout>
...
</RelativeLayout>
The above seems to put the image somewhere in the center. How do I ensure that the image is right aligned regardless of whether we are in portrait or landscape mode?
Thanx!
Upvotes: 6
Views: 17451
Reputation: 1314
Following seems to work. Two changes 1. use orientation = vertical as suggested by Zortkun 2. Use wrap_content in layout_width.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/settingsIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/settings_icon" >
</ImageView>
</LinearLayout>
Upvotes: 7
Reputation: 7268
The default orientation of LinearLayout
is horizontal. Make sure the Linear layout's orientation is set to Vertical ortherwise you cannot aling stuff horizontally.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
Upvotes: 0
Reputation: 4695
You don't need a Linearlayout if you use only one view inside the Linearlayout.
Anyway its here,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
//...some other elements
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:id="@+id/imageIcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/image_icon" >
</ImageView>
</LinearLayout>
</RelativeLayout>
Upvotes: 0