2014-01-08 142 views
0

我有这样的布局,是一个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> 

enter image description here

我有麻烦添加另一个按钮到左(...)按钮。

我想添加的按钮,该行将保持其比例(走线的所有宽度)

任何想法?

+0

你可以添加整个XML代码? –

回答

1

据我所见,您正在使用水平LinearLayout作为您的项目的根布局。我会将其更改为RelativeLayout。此外,如果你需要你的布局占据整个宽度 - 你需要摆脱200dip硬编码,并与match_parent

这里替换它是我得到使用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> 

enter image description here