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!
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
You can set the android:layout_weight='1' and both buttons will share the screen equally(side by side) or if you want the extra space between them, you can place a button each in a linear layout and set the android:layout_gravity to left and right for each. Save this answer.
To center align LinearLayout, assign android:gravity attribute of this LinearLayout with the value “center”.
We can use LinearLayout inside RelativeLayout.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With