所以我想在屏幕顶部有一个有两个按钮的linearLayout,在底部有一个也有两个按钮的linearLayout,在中间有一个listView。我遇到的问题是,如果listView变得太大,底部的linearLayout就会被覆盖。我将listView告诉wrap_content,因为它是layout_height,因为我想做that...but,我几乎可以肯定,这就是底部linearLayout没有显示的原因。代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/importClasses"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
</Button>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/Title"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical|center"
>
</TextView>
<Button
android:id="@+id/addClasses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<ListView
android:id="@+id/classList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/topLayout" >
</ListView>
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/classList"
>
<Button
android:id="@+id/Assignments"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
</Button>
<Button
android:id="@+id/flashCards"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
有什么建议吗?
发布于 2012-09-21 09:36:38
将classList
设置为高于bottomLayout
、低于topLayout
。
还将bottomLayout
设置为layout_alignParentBottom="true"
和topLayout layout_alignParentTop="true"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_alignParentTop="true">
<Button
android:id="@+id/importClasses"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
</Button>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/Title"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical|center"
>
</TextView>
<Button
android:id="@+id/addClasses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<ListView
android:id="@+id/classList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottomLayout"
android:layout_below="@+id/topLayout" >
</ListView>
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/Assignments"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
</Button>
<Button
android:id="@+id/flashCards"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
发布于 2012-09-21 09:37:59
这应该是可行的,但您可能需要将RelativeLayout
更改为LinearLayout
。
并将ListView
的layout_height
更改为0dp
,并在其中添加layout_weight="1"
。
https://stackoverflow.com/questions/12522776
复制相似问题