Reputation: 4042
I have a multi-line TextView and next to it I want to show a checkbox. The problem is that if the text stretches across more than 1 row, the checkbox isn't displayed.
So far, I have (without the ids):
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="left"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="left"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="5dp"
android:singleLine="false"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text=""
android:clickable="false" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:singleLine="false"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
This is how the layout is rendered (notice the missing checkbox):
If I shorten the text, it's rendered correctly:
Is it possible to add a CheckBox at the right of a multi-line TextView?
Edit: Sorry everyone, I solved the problem pretty soon after asking this question (by adding layout_weight=1), but posted in a wrong thread. I have accepted the answer suggesting that.
Upvotes: 2
Views: 12479
Reputation: 4140
Add this android:layout_weight="1"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="left"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="left"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="5dp"
android:singleLine="false"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:text=""
android:clickable="false"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:singleLine="false"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
Upvotes: 5
Reputation: 21181
try to use the following in a LinearLayout
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textfield 1-1"></TextView>
<CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
Copied from http://huuah.com/using-tablelayout-on-android/
Upvotes: 1
Reputation: 6518
You can do this by using weights.. try following code
Please try to change weights according to your requirement
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="left"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="3dp"
android:paddingTop="5dp"
android:singleLine="false"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:focusable="false"
android:text=""
android:clickable="false" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:singleLine="false"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:textAppearance="?android:attr/textAppearanceSmall" />
Upvotes: 1
Reputation: 5322
Try giving the CheckBox
a Weight
value greater than the TextView
(set its width
to 0dip
and give it higher Weight
)
Upvotes: 1
Reputation: 22146
Try to use a relative layout inside your linear layout instead of a linear layout inside a linear layout and use relative layout parameters.
Upvotes: 2