Reputation: 5840
I have this layout which is a row item of a ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:clickable="true"
android:gravity="center" >
<ToggleButton
android:id="@+id/taskActiveToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="ToggleButton" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/taskNameTextView"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/taskScheduleTextView"
android:layout_width="200dp"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="@+id/taskMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="..." /></LinearLayout>
I am having troubles adding another button to left of the (...) button.
I want to add the button so the row will keep its proportions (take all width of the line)
Any ideas?
Upvotes: 0
Views: 1075
Reputation: 20934
As far as I can see, you are using horizontal LinearLayout
as a root layout for your items. I would change it to RelativeLayout
. Also if you need your layout occupy the whole width - you need to get rid of 200dip
hardcoding and replace it with match_parent
Here is what I got using RelativeLayout
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ToggleButton
android:id="@+id/taskActiveToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:text="ToggleButton" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/taskActiveToggleButton"
android:layout_toLeftOf="@+id/anotherButton"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="@+id/taskNameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text" />
<TextView
android:id="@+id/taskScheduleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sub Text"/>
</LinearLayout>
<Button
android:id="@+id/anotherButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@+id/taskMenuButton"
android:text="But2" />
<Button
android:id="@+id/taskMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:text="..." />
</RelativeLayout>
Upvotes: 1