问题
Hi and thanks for your help!
This is my desired result:
This is my XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<include
android:layout_height="wrap_content"
layout="@layout/filelist" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
where filelist.xml is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/scanning" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fastScrollEnabled="true"
android:layout_marginLeft="@dimen/list_margin"
android:layout_marginRight="@dimen/list_margin"
android:background="?attr/listBackground" >
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/this_folder_is_empty"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
This is what I get instead
回答1:
You need to make your parent ViewGroup
(your root node in the layout file) a RelativeLayout
and then specify android:layout_above="@id/THE_BUTTON_CONTAINER
on the LinearLayout
that holds the list.
The system will then ignore all intents of the list to make itself larger.
android:layout_above
and android:layout_below
are very handy methods when it comes to placing containers of which you don't know the size yet and I use them frequently. An example as follows:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/myMenuBar"
android:layout_below="@+id/myStatusBar" >
Regards
回答2:
This might work.
Inside filelist.xml change
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
To
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
回答3:
You can add include tag in linear layout like this -:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:layout_height="wrap_content"
layout="@layout/filelist" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
This may help you.I dont know whether this is a right approach but for now may be the solution for you.
来源:https://stackoverflow.com/questions/18424117/my-listview-of-my-viewfilipper-fills-the-parent-and-buttons-on-the-bottom-get