我想在左側放置一個TextView,並在TextView的右側放置一個控件(例如CheckBox)。我希望控件在屏幕上左對齊。這並不難通過LinearLayout或RelativeLayout獲得。比如我這樣做與LinearLayout中: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