2014-01-08 2 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

Смежные вопросы