RelativeLayout 布局问题!

问题描述

RelativeLayout 布局问题!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_below="@+id/list"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/UserIDStatic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/UserID" />
        .
        .
        .
    </LinearLayout>

</RelativeLayout>

如上所示的布局,当list中条目太多,超过一屏的时候,向下拖动,看不到下面的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" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >
    </ListView>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/UserIDStatic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="wsws" />
    </LinearLayout>

</LinearLayout>

解决方案二:

把代码改成这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
        <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="100dp" >   <!-- use a definate dimension here -->
    </ListView>
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_below="@+id/list"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >
       <TextView
            android:id="@+id/UserIDStatic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/UserID" />
        .
        .
        .
    </LinearLayout>
 </RelativeLayout>

或者把 ListView 和 LinearLayout 放在 ScrollView
或者按照下面的方法

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
android:weightSum="1"
android:orientatio="verticle" >
        <ListView
            android:id="@+id/list"
           android:layout_weight="0.5"
            android:layout_width="match_parent"
            android:layout_height="0dp" >
        </ListView>
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="0.5"
            android:orientation="horizontal" >
        <TextView
                android:id="@+id/UserIDStatic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/UserID" />
            .
            .
            .
        </LinearLayout>
      </LinearLayout>

解决方案三:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <ListView android:id="@android:id/list"
            style="?android:attr/listViewWhiteStyle"
               android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:drawSelectorOnTop="false"
            android:scrollbarStyle="insideOverlay"
            android:listSelector="#00000000"
            android:cacheColorHint="@android:color/white"
            android:fadingEdgeLength="16dip" />
    </FrameLayout>     

     <LinearLayout
         android:layout_width="match_parent"
            android:gravity="bottom"
            android:layout_height="wrap_content" >
        <TextView
            android:layout_width="match_parent"
               android:gravity="bottom"
               android:layout_height="wrap_content"
               android:text="akdsflksfopiapdofaipo"  />
    </LinearLayout>

</LinearLayout>

这样应该可以,主要想法是让你的下面的布局不要和listview平级,所以给listview外面加上一个布局,加的这个布局和下面布局平级。

时间: 2024-08-03 10:40:09

RelativeLayout 布局问题!的相关文章

Android AbsoluteLayout和RelativeLayout布局详解_Android

Android 线性布局: AbsoluteLayout布局和RelativeLayout布局.  1.绝对布局 AbsoluteLayout 绝对定位AbsoluteLayout,又可以叫做坐标布局,可以直接指定子元素的绝对位置,这种布局简单直接,直观性强,但是由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差. 下面我们举一个例子看看:例子里的机器人图片大小是250X250,可以看到我们使用android:layout_x和android:layout_y来指定子元素的纵横坐标. <?

Android AbsoluteLayout和RelativeLayout布局详解

Android 线性布局: AbsoluteLayout布局和RelativeLayout布局. 1.绝对布局 AbsoluteLayout 绝对定位AbsoluteLayout,又可以叫做坐标布局,可以直接指定子元素的绝对位置,这种布局简单直接,直观性强,但是由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差. 下面我们举一个例子看看:例子里的机器人图片大小是250X250,可以看到我们使用android:layout_x和android:layout_y来指定子元素的纵横坐标. <?x

Android常用布局控件之RelativeLayout

我们使用LinearLayout和TableLayout可以满足开发应用程序界面基本的要求 .但是有时候实现界面的时候不够灵活,我们还可以使用另外一种控件 RelativeLayout.RelativeLayout是一种相对布局的控件,这个容器内部的子元 素们可以使用彼此之间的相对位置或者和容器间的相对位置来进行定位,类似于 网页设计中的CSS.在指定控件的位置时,我们需要指定这个控件与其它控件之 间的相对位置关系,比如说与另一个控件的左边对齐,右对齐,位于另一个控件 的上方,下方等等.一个控件

Android开发入门(五)屏幕组件 5.5 RelativeLayout相对布局

使用RelativeLayout,可以通过设置"相对位置"(每个View相对于另一个view的位置),来指定它所包 含的子view的位置.看下面main.xml中的代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" androi

android LinearLayout和RelativeLayout实现精确布局

先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距 padding:是 控件的内容相对控件的边缘的边距. margin  :是控件边缘相对父空间的边距 android:gravity是 对该view 内容的限定. 比如一个button 上面的text. 你可以设置该text 在view的靠左,靠右等位置.该属性就干了这 个. android:layout_gravity 是用来设置该view中的子view相对于父view的位置. 比如一个bu

Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout实例详解_Android

本文实例分析了Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout.分享给大家供大家参考,具体如下:  一.绝对布局AbsoluteLayout 绝对定位AbsoluteLayout,又可以叫做坐标布局,可以直接指定子元素的绝对位置,这种布局简单直接,直观性强,但是由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差. 下面我们举一个例子看看:例子里的机器人图片大小是250X250,可以看到我们使用android:layout_x和android:l

Android零基础入门第28节:轻松掌握RelativeLayout相对布局

原文:Android零基础入门第28节:轻松掌握RelativeLayout相对布局 在前面三期中我们对LinearLayout进行了详细的解析,LinearLayout也是我们用的比较多的一个布局.但在实际开发中使用LinearLayout远远不够,我们本期一起来学习RelativeLayout.     一.认识RelativeLayout RelativeLayout,又叫相对布局,使用RelativeLayout标签.相对布局通常有两种形式,一种是相对于容器而言的,一种是相对于控件而言的

简析Android五大布局(LinearLayout、FrameLayout、RelativeLayout等)_Android

Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Android的五大布局分别是LinearLayout(线性布局).FrameLayout(单帧布局).RelativeLayout(相对布局).AbsoluteLayout(绝对布局)和TableLayout(表格布局). 布局一:LinearLayout LinearLayout按照垂直或者水平的顺序依次排列子元素,每一个子元素都位于前一个元

Android布局(RelativeLayout、TableLayout等)使用方法_Android

 本文介绍 Android 界面开发中最基本的四种布局LinearLayout.RelativeLayout.FrameLayout.TableLayout 的使用方法及这四种布局中常用的属性. LinearLayout 线性布局,布局中空间呈线性排列 RelativeLayout 相对布局,通过相对定位的方式,控制控件位置 FrameLayout 帧布局,最简单的布局,所有控件放置左上角 TableLayout 表格布局,以行列方式控制控件位置 四种布局示例 1.LinearLayout <L