Hong Wei Wang Hong Wei Wang - 6 days ago 5
Java Question

Why doesn't my linear layout match my parent height in listview?

I have the following code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/list_view_layout_margin"
android:paddingRight="@dimen/list_view_layout_margin"
android:background="@color/yellow">

<LinearLayout
android:id="@+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/gameNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/game_list_text_size" />

<TextView
android:id="@+id/gameCreationDateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textSize="@dimen/small_text_size"
android:textStyle="italic" />
</LinearLayout>

<LinearLayout
android:id="@+id/LinearLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:orientation="horizontal" >

<Button
android:id="@+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info" />

<Button
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/delete" />
</LinearLayout>


</RelativeLayout>


The LinearLayout with id itemLinearLayoutView is the main layout that wrap everything in a row of listview. The problem I am having is that the second linear layout child does not take the height of the parent linear layout with id itemLinearLayoutView. Any solutions? or Problem with the code?

Answer

Your problem lies here:

android:layout_height="wrap_content"

This needs to be changed to "match_parent" in the LinearLayout which you want to be the parent's size. Also, you said

the second linear layout child does not take the height of the parent linear layout

These two layouts are not parents and children to one another. The parent is your RelativeLayout and both of your LinearLayouts are equivalent children of that RelativeLayout. Maybe this will help you debug any further problems you encounter.