这是我正在使用的代码,它不起作用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView android:text="TextView" android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right">
</TextView>
</LinearLayout>
无需使用任何额外的视图或元素:
//这是如此简单
<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:text="No. of Travellers"
android:textColor="#000000"
android:layout_weight="1"
android:textStyle="bold"
android:textAlignment="textStart"
android:gravity="start" />
//这是正确的对齐
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
android:layout_weight="1"
android:textAlignment="textEnd"
android:gravity="end" />
</LinearLayout>
添加视图有点困难,它覆盖了所有的屏幕宽度,像这样:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
试试下面的代码:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Account"/>
</LinearLayout>