我想在TextView的右侧放置一个TextView,在TextView的右侧放置一个控件(例如,一个CheckBox).我希望控件在屏幕上左对齐.这并不难通过LinearLayout或RelativeLayout获得.例如,我使用LinearLayout执行此操作
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/todo_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Small"
android:maxLines="2"
android:textStyle="bold" />
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<CheckBox
android:id="@+id/todo_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:focusable="false"/>
</LinearLayout>
问题是,当TextView的文本太长时,它会将复选框推出屏幕,并且复选框不再可见.相反,我希望复选框固定在屏幕的右端,如果需要,TextView最终会分成两行.
我怎样才能做到这一点?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/todo_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Small"
android:maxLines="2"
android:layout_weight="1"
android:textStyle="bold" />
<CheckBox
android:id="@+id/todo_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:focusable="false"/>
</LinearLayout>
