У меня есть простая LinearLayout с одним TextView и одним ImageView. Я хочу, чтобы текст в TextView был выровнен по правому краю, но результат показывает, что текст выровнен по левому краю. Что-то не так с моим макетом XML? Спасибо.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#E8E3E4">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<TextView android:layout_width="260dp" android:layout_height="wrap_content"
android:text="More Comments" android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp"
android:layout_height="wrap_content" android:src="@drawable/arrow_right"
android:layout_gravity="center" android:scaleType="centerInside" />
</LinearLayout>
</LinearLayout>
Спасибо, Майкл. Но упомянутый вами обходной путь тоже не работает.
Я пытался использовать RelativeLayout, но он все равно дал мне результат, например:
Больше комментариев (Иконка)
То, что я ожидал,
Больше комментариев (Иконка)
RelativeLayout xml находится ниже. Что-то не так с этим?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/label" android:layout_width="260dp"
android:layout_height="wrap_content" android:text="More Comments"
android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp" android:layout_height="wrap_content"
android:src="@drawable/arrow_right" android:layout_gravity="center"
android:scaleType="centerInside" android:layout_toRightOf="@id/label" />
</RelativeLayout>
После обходного пути в комментарии Майкла у меня есть XML ниже. Я ожидал, что результат будет:
RightLeft
но фактический результат:
Right Left
Так что обходной путь не работает для меня. Есть мысли?
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1.0"
android:text="RIGHT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="LEFT"/>
</LinearLayout>