0

我已经搜索了如何将应用程序对齐到右侧以及从右到左写入的文本。
我发现并成功做的唯一一件事是通过添加 EditText 和 Button 使文本从右到左书写android:gravity="right"
,但如果从左到右,它们仍然在行中排序。
activity_main.xml 文件 -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:gravity="right"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <EditText android:id="@+id/text_message"
     android:gravity="right"
     android:layout_weight="1.0"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:hint="@string/text_message" />

    <Button android:layout_height="wrap_content"
     android:gravity="right"
     android:layout_width="wrap_content"
     android:text="@string/send_button"
     android:onClick="ButtonClicked" />

    <Button android:layout_height="wrap_content"
     android:gravity="right"
     android:layout_width="wrap_content"
     android:text="@string/delete_button"
     android:onClick="DeleteClicked" />

</LinearLayout>

我在“排序是从左到右”的意思是 EditText 写在“发送”按钮之前,而“发送”按钮 id 写在“删除”按钮之前 - 所以显示的是
“[ _ ___ x ] [Send][Delete]" 而不是 "[Delete][Send][ _ ____ ]",就像我想要的那样。

4

3 回答 3

1

您可以使用代替LinearLayoutRelativeLayout并使用给您的按钮一些 id

android:id="@+id/your_button_id

然后使用标签android:layout_toRightOfandroid:layout_toLeftOf. 在你的情况下,是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" >

<Button android:id="@+id/delete_button" 
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:text="@string/delete_button"
 android:onClick="DeleteClicked" />

<Button android:id="@+id/send_button" 
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:layout_toRightOf="@+id/delete_button"
 android:text="@string/send_button"
 android:onClick="ButtonClicked" />

<EditText android:id="@+id/text_message"
 android:layout_weight="1.0"
 android:layout_width="0dp"
 android:layout_toRightOf="@+id/send_button"
 android:layout_height="wrap_content"
 android:hint="@string/text_message" />

</RelativeLayout>
于 2012-07-09T17:58:40.623 回答
0

尝试使用

android:layout_gravity

您也可以只使用 RelativeLayout 添加

android:align_ParentRight="true"
于 2012-07-09T17:51:01.347 回答
0

改变

android:gravity="right"

android:layout_gravity="right"
于 2012-07-09T18:22:34.243 回答