我想在屏幕左侧添加一个TextView,右侧放置一个控件(例如CheckBox)。我希望该控件在屏幕上左对齐。这可以通过LinearLayout或RelativeLayout很容易实现。例如,我可以使用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="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最终会分为两行。 如何实现这一点?
layout_weight
和weightsum
来布局吗? - chancea