首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >relativeLayout危机

relativeLayout危机
EN

Stack Overflow用户
提问于 2012-09-21 08:27:28
回答 2查看 78关注 0票数 0

所以我想在屏幕顶部有一个有两个按钮的linearLayout,在底部有一个也有两个按钮的linearLayout,在中间有一个listView。我遇到的问题是,如果listView变得太大,底部的linearLayout就会被覆盖。我将listView告诉wrap_content,因为它是layout_height,因为我想做that...but,我几乎可以肯定,这就是底部linearLayout没有显示的原因。代码如下:

代码语言:javascript
运行
复制
<?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>

有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-21 09:36:38

classList设置为高于bottomLayout、低于topLayout

还将bottomLayout设置为layout_alignParentBottom="true"topLayout layout_alignParentTop="true"

代码语言:javascript
运行
复制
<?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>

票数 1
EN

Stack Overflow用户

发布于 2012-09-21 09:37:59

这应该是可行的,但您可能需要将RelativeLayout更改为LinearLayout

并将ListViewlayout_height更改为0dp,并在其中添加layout_weight="1"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12522776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档