Reputation: 1055
How do I rightalign an imageview in a linearlayout - that is put the imageview to the right side of the linearlayout parent? android:layout_alignparent is not allowed in a LinearLayout. And I have tried with different gravity-constants.
This is a depiction of the screen and where I want to position the imageview. Its assumed that the parent is a linearlayout and orients its child in a horizontal order.
______________________
| |
| |
| X|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|____________________|
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageView
android:id="@+id/dateImg"
android:layout_width="60dp"
android:layout_height="64dp"
android:layout_marginLeft="8dp"
android:layout_gravity="end"
android:src="@drawable/unchecked"/>
</LinearLayout>
Upvotes: 1
Views: 5440
Reputation: 111
Change orientation to "vertical":
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="60dp"
android:layout_height="64dp"
android:layout_marginLeft="8dp"
android:layout_gravity="end"
android:background="#000000">
</ImageView>
Upvotes: 1
Reputation: 209
Have you tried
android:gravity="right"
Anyways in my opinion RelativeLayout is better for stuff like that :)
Upvotes: 0
Reputation: 1192
Can you try this
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="0dp"
android:layout_weight="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2">
<ImageView
android:id="@+id/dateImg"
android:layout_width="60dp"
android:layout_height="64dp"
android:layout_marginLeft="8dp"
android:alignParentRight="true"
android:src="@drawable/unchecked"/>
</RelativeLayout>
</LinearLayout >
Upvotes: 0
Reputation: 628
Why can't you use a relative layout instead ?
Or in case you must use a linear layout , add another view before the image view like this -
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="0dp"
android:layout_weight="1" >
<View
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/dateImg"
android:layout_width="60dp"
android:layout_height="64dp"
android:layout_marginLeft="8dp"
android:layout_gravity="end"
android:src="@drawable/unchecked"/>
enter code here
Upvotes: 1