Android 安卓填充父问题
你好。这是我的布局Android 安卓填充父问题,android,Android,你好。这是我的布局 <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
<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。谢谢我想你可以做到: 写:
<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" />
但我不确定mnish是否正确,除了在安卓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" />
你可以使用上面的layout\u,下面的layout\u,layout\u toLeftOf,在尝试了一些可能性之后,我发现这很有帮助
<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>
谢谢大家的回答。我认为
线性布局更适合这里
<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\u content
在ListView
的layout\u height
上是正确的,layout\u weight=“1”
将确保其尽可能扩展)这是正确的。但是,由于我提到了“填充父对象”作为高度,因此该按钮不可见。请将android:layout\u alignParentTop=“true”放在ListView上以防止出现这种情况。您不能这样做。必须先声明listview,然后才能引用它。相反,将按钮设置为alignparentbottom,然后将listview设置在其上方