安卓:添加组件的RelativeLayout [英] Android: adding components to RelativeLayout

查看:208
本文介绍了安卓:添加组件的RelativeLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的屏幕上,我想有夏理(尤其是图像)的顶部和列表,并在底部我想有小imagebuttons(如YouTube和Facebook)。

我使用的RelativeLayout ..前两个正确显示,最后一个根本不显示在屏幕上,任何人都可以有所帮助。

我的布局文件看起来像这样

 <&RelativeLayout的GT;
    <图像>< /图片>
    <&的ListView GT;< /&的ListView GT;
    <&RelativeLayout的GT;
        <&的ImageButton GT;< / ImageButton的>
    < / RelativeLayout的>
< / RelativeLayout的>


解决方案

RelativeLayout的它的事项中,命令你添加子视图(因为后者可以绑定为增加previously的那些)。

我认为这是你的布局问题,你有一个 FILL_PARENT / match_parent 高看已经内侧(的ListView ),并没有空间页脚。

您应该改变你的视图中的 RelativeLayout的命令:


  1. 首先,你应该添加标题视图
    (并将其绑定到顶部:的android:align_parent_top =真正的),然后

  2. 的按钮页脚(并将其绑定
    底部:的android:align_parent_bottom =真正的)和

  3. 的ListView 应该填写
    空的空间会去的
    三分之二查看,与
    的android:layout_below =header_view

    的Adroid:layout_above =footer_view`

那么您的布局看起来像:

 <?XML版本=1.0编码=UTF-8&GT?;
<&RelativeLayout的GT;
    <图像机器人:ID =@ + ID /头
        机器人:layout_alignParentTop =真正的>< /图片>
    < RelativeLayout的机器人:ID =@ + ID /页脚
        机器人:layout_alignParentBottom =真正的>
        <&的ImageButton GT;< / ImageButton的>
    < / RelativeLayout的>
    < ListView控件
        机器人:layout_below =@ ID /头
        机器人:layout_above =@ ID /页脚>< /&的ListView GT;
< / RelativeLayout的>

in My screen, i want to have Hearder(specifically image) on top, and List, and at bottom i want to have small imagebuttons (like youtube,facebook).

I'm using RelativeLayout.. first two are displaying correctly, last one not display at all on the screen, can anyone help here.

my layout file looks like this

<RelativeLayout>
    <image></image>
    <ListView></ListView>
    <RelativeLayout>
        <ImageButton></ImageButton>
    </RelativeLayout>
</RelativeLayout>

解决方案

In a RelativeLayout it matters in which order you add the child views (since the latter can be bound to the ones added previously).
I think this is the problem in your layout, you have a fill_parent/match_parent high view already inside (the ListView), and there is no room for the footer.

You should change the order of your views inside the RelativeLayout:

  1. first you should add the header view (and bind it to the top: android:align_parent_top="true"), then
  2. the footer with buttons (and bind it to the bottom: android:align_parent_bottom="true"), and
  3. the ListView which should fill up the empty space will go in as the thirds view, with android:layout_below="header_view" and adroid:layout_above="footer_view"`

Your layout would then look like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
    <image android:id="@+id/header" 
        android:layout_alignParentTop="true"></image>
    <RelativeLayout android:id="@+id/footer"
        android:layout_alignParentBottom="true">
        <ImageButton></ImageButton>
    </RelativeLayout>
    <ListView
        android:layout_below="@id/header" 
        android:layout_above="@id/footer"></ListView>
</RelativeLayout>

这篇关于安卓:添加组件的RelativeLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆