I want to bring the left image to the right, but I can not do it. I know that I can use Layout_Direction="rtl"
But I do not want to use it. On some phones, Layout is damaged
this is my layout.xml
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:minHeight="?attr/actionBarSize"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_large"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/icon_front"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillAfter="false"
android:fillEnabled="false">
<ImageView
android:id="@+id/icon_profile"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="@dimen/spacing_medium"
android:layout_height="0dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/message_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical"
android:paddingTop="@dimen/spacing_middle"
android:paddingBottom="@dimen/spacing_middle">
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_middle"
android:gravity="right"
android:maxLines="1"
android:text="People Name"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_medium"
android:layout_marginEnd="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_middle"
android:gravity="right"
android:maxLines="1"
android:text="some new text for new items"
android:textAppearance="@style/TextAppearance.AppCompat.Small"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey_10" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
So How can I put the image on the right? Also, the gravity does not work I tried the use of gravity but did not move the image to the right
The ImageView
is inside a RelativeLayout
, so you need to add this atribute:
android:layout_alignParentEnd="true"
or if you don't need RTL support:
android:layout_alignParentRight="true"
and the xml will be:
<ImageView
android:id="@+id/icon_profile"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.