代码之家  ›  专栏  ›  技术社区  ›  Prabhat

安卓填充父问题

  •  2
  • Prabhat  · 技术社区  · 15 年前

    你好。这是我的布局

    <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" />
        <Button android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_below="@id/lv" />
    </RelativeLayout>
    

    当我运行这个时,列表视图将占据全屏。我想要的是列表视图是全屏的,除了按钮区域没有提到dp。谢谢

    4 回复  |  直到 15 年前
        1
  •  1
  •   fedj    15 年前

    @mnish是非常正确的,除了在android 1.5中,在使用ID之前必须声明它们。

    <ListView android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white" />
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/lv" />
    

    你可以使用上面的布局,下面的布局,布局到左…

        2
  •  1
  •   Prabhat    15 年前

    在尝试了一些可能性之后,我发现这是有帮助的

    <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"/>
    </RelativeLayout>
    

    谢谢大家的回答。

        3
  •  1
  •   Felix    15 年前

    我想A LinearLayout 更适合这里。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >
        <ListView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_weight="1"
             />
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>
    

    (是的, wrap_content 正确打开 ListView layout_height , the layout_weight="1" 确保尽可能扩大)

        4
  •  0
  •   mnish    15 年前

    我想你可以这样做:

    写:

    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/lv" />
    

    之前:

    <ListView android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white" />
    

    这样地:

    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/lv" />
    
    <ListView android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white" />
    

    但我不确定