[英]bring the left image to the right in LinearLayout
我想將左邊的圖像移到右邊,但是我做不到。 我知道我可以使用Layout_Direction="rtl"
但我不想使用它。 在某些手機上,布局已損壞
這是我的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>
那么如何將圖像放在右邊? 另外,重力不起作用,我嘗試使用重力,但沒有將圖像向右移動
ImageView
位於RelativeLayout
內部,因此您需要添加以下屬性:
android:layout_alignParentEnd="true"
或者如果您不需要RTL支持:
android:layout_alignParentRight="true"
xml將是:
<ImageView
android:id="@+id/icon_profile"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.