2016-07-21 9 views
1

Ich habe ein ListView, das Element ist ein RelativeLayout, links ist Text und die rechte Seite ist ImageView in einem LinearLayout.
Ich erwarte, dass die Höhe des LinearLayout ** (weißer Hintergrund) ** fillParent ist, aber nicht.
Der Effekt ist:
enter image description here
Jeder kann dabei helfen?Android: Höhe von LinearLayout füllte nicht Eltern des ListView-Elements

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_list_item" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/main_list_item_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/main_list_item_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/main_list_item_more" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/main_list_item_delete_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:background="#ffffff" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/main_list_item_delete" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/main_list_item_check_margin_lr" 
      android:layout_marginRight="@dimen/main_list_item_check_margin_lr" 
      android:contentDescription="@string/none" 
      android:gravity="center" 
      android:src="@drawable/ic_ctx_del1" /> 
    </LinearLayout> 

</RelativeLayout> 




Die main.xml ist als unten, um die Listview enthält:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="fill" 
    android:orientation="vertical" > 

    <!-- content --> 
    <LinearLayout 
     android:id="@+id/center" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="@dimen/main_margin" 
     android:layout_marginRight="@dimen/main_margin" 
     android:orientation="vertical" 
     android:layout_above="@id/adview_ayout"> 

     <ListView 
      android:id="@+id/main_list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
     </ListView> 

    </LinearLayout> 
    <!-- content end --> 

    <LinearLayout 
     android:id="@+id/main_layout_pb" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@android:color/transparent" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:clickable="true" 
     android:visibility="gone"> 

     <ProgressBar 
      android:id="@+id/main_pb" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|center_horizontal" > 
     </ProgressBar> 
    </LinearLayout> 

enter code here

+0

Fügen Sie dem 'LinearLayout' Attribute' layout_alignParentTop' und 'layout_alignParentBottom' hinzu und setzen Sie beide auf' true'. –

+0

Bitte zeigen Sie Ihr Layout mit dem Listenansicht –

+0

Was LinearLayout? Was möchtest du wirklich? –

Antwort

0

Ich glaube, das ist etwas, das die Mutter RelativeLayout von nicht verarbeiten kann selbst - es schafft Art von einem Teufelskreis - Eltern verlagert die Höhe auf das Kind (wrap_content auf der RelativeLayout) und das Kind verschiebt die Höhe zum Eltern (match_parent auf main_list_item_delete_layout). Was Sie tun können, ist die Spitze des main_list_item_delete_layout an die Eltern und seiner Unterseite zu einer anderen Ansicht zu verankern, die den Boden sein, garantiert (die LinearLayout auf der linken Seite, die drei Textansichten enthalten):

<RelativeLayout ...> 
    <LinearLayout 
     android:id="@+id/left_layout" 
     android:layout_toLeftOf="@+id/main_list_item_delete_layout" 
     android:layout_toStartOf="@+id/main_list_item_delete_layout" 
     ... 
    > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/main_list_item_delete_layout" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignBottom="@id/left_layout" 
     ...> 
    </LinearLayout> 
</RelativeLayout> 

PS: Wenn der Text auf der linken Seite LinearLayout zu lang ist, wird er überlaufen und das Löschlayout überlappen - daher der Zusatz des Ankers, den ich dem linken Layout hinzugefügt habe. PS2: Ich weiß, dass diese Lösung sehr an Ihr Layout angepasst ist. Wenn Sie die als übergeordnetes Element verwenden möchten, sollten Sie die neue Version ConstraintLayout ausprobieren.

+0

Sie sind absolut richtig, vielen Dank – Lune

Verwandte Themen