Reputation: 13
I'm trying to use layout_weight and layout_width with a linear layout with horizontal orientation. The linear layout contains 1 TextView and 2 RadioButtons (in a RadioButtonGroup). I'd like the TextView to fill up the space to the left of the RadioButtons and always keep the RadioButtons right-justified on the screen. So regardless of the amount of text, the TextView should take up the space so that the RadioButtons are always right-justified. The LinearLayout is used in a ListView to have multiple rows in the list.
Unfortunately, the TextView is wrapping content despite specifying android:layout_width="0dp" and android:weight="1". And the RadioButtons are not lined up on the right nicely.
Here's the image
Here's the XML for the LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scrollbarAlwaysDrawVerticalTrack="false" >
<TextView
android:id="@+id/jokeTextView"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center_vertical"/>
<RadioGroup
android:id="@+id/ratingRadioGroup"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<RadioButton
android:id="@+id/likeButton"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:button="@drawable/like"
android:gravity="right"/>
<RadioButton
android:id="@+id/dislikeButton"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:button="@drawable/dislike"
android:gravity="right"/>
</RadioGroup>
</LinearLayout>
I also tried it with setting RadioButton android:layout_width="wrap_content" which did not work either. Any help would be appreciated.
Upvotes: 0
Views: 2333
Reputation: 986
If you want a layout on one side and one on the other, use RelativeLayout: alignParentRight/Left.
Upvotes: 0
Reputation: 17085
Issue is with your listview. There is no issue with the item layout
Change your listview
android:layout_width="match_parent""
Upvotes: 0
Reputation: 24853
Try this..
I guess your listview width as wrap_content
change it as match_parent
and try
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Upvotes: 2