1

为了防止多个 GetView 调用,我将 ListView 的高度设置为 fill_parent。

如何显示 ListView 本身以外的其他视图?

以下布局在 ViewPager 中膨胀:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="15dp" >

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

    <include layout="@layout/activity_prontuario_home" />
</LinearLayout>

其中包含的布局是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="20dp" >

    <ScrollView
        android:id="@+id/prontuariohome_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none" >
        .
        .
        .
        .
    </ScrollView>

</LinearLayout>

编辑:此解决方案不适用于高于按钮的视图

4

5 回答 5

1

I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="15dp" >

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >
        <ListView android:id="@+id/lv_viol_infraction"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <include layout="@layout/activity_prontuario_home" />
</LinearLayout>
于 2013-11-11T09:38:10.610 回答
0

I'm sorry for being not clear.

Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.

After some tries I'm happy to give you the solution of my problem.

Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="15dp" >

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ListView android:id="@+id/lv_viol_infraction"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <include layout="@layout/activity_prontuario_home" />
</LinearLayout>
于 2013-11-11T09:39:01.947 回答
0

你说这个解决方案是行不通的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/lv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" android:layout_above="@+id/bt"/>
<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:id="@+id/bt" android:layout_alignParentBottom="true"/>

只需将其添加android:layout_above="@+id/bt"到列表视图。

于 2013-11-11T09:36:52.730 回答
0

使用 android:layout_height="0dip" 视图将占据剩余的空闲位置

于 2013-11-11T09:31:26.507 回答
0

尝试使用以下代码

android:layout_height="0dp"
android:layout_weight="1" 

ListView标签中

于 2013-11-11T09:24:24.913 回答