有什么毛病我包括RelativeLayout的? [英] What's wrong with my include in RelativeLayout?

查看:105
本文介绍了有什么毛病我包括RelativeLayout的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个在顶部标题栏和底部的导航栏中选择一个活动。我用包括包括标题栏布局和导航栏布局到主布局正如你可以看到下面。其结果是,无论是标题栏和导航条转到屏幕的顶部。有人能告诉我为什么吗?谢谢!

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / home_widget机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@可绘制/背景>

    <包括机器人:ID =@ + ID / title_bar布局=@布局/ title_bar
        机器人:layout_alignParentTop =真/>

    <包括机器人:ID =@ + ID / navigation_bar布局=@布局/ navigation_bar
        机器人:layout_alignParentBottom =真/>
< / RelativeLayout的>
 

我没有找到问题的根源。但以下工作:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / home_widget
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@可绘制/背景>

< RelativeLayout的机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentTop =真
    机器人:ID =@ + ID / title_bar>

    <包括布局=@布局/ title_bar/>
< / RelativeLayout的>

< RelativeLayout的机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:ID =@ + ID / navigation_bar>

    <包括布局=@布局/ navigation_bar/>
 < / RelativeLayout的>
 

解决方案

为了覆盖你,包括布局的属性,还必须同时覆盖布局宽度和布局的高度。如果这两方面的设置不会被覆盖,其他任何布局更改尝试都将被忽略。

您的布局上面

 <包括机器人:ID =@ + ID / title_bar布局=@布局/ title_bar
    机器人:layout_alignParentTop =真
/>
<包括机器人:ID =@ + ID / navigation_bar布局=@布局/ navigation_bar
    机器人:layout_alignParentBottom =真/>
 

实际上应与包装内容或填写家长酌情。

 <包括机器人:ID =@ + ID / navigation_bar布局=@布局/ navigation_bar机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真/>
 

I want to create an activity with a title bar at top and a navigation bar at bottom. I used include to include the title bar layout and the navigation bar layout into the main layout as you can see below. The result is that both the title bar and navigation bar go to the top of the screen. Could someone tell me why? Thanks!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_widget" android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/background">

    <include android:id="@+id/title_bar" layout="@layout/title_bar" 
        android:layout_alignParentTop="true" />

    <include android:id="@+id/navigation_bar" layout="@layout/navigation_bar" 
        android:layout_alignParentBottom="true"/> 
</RelativeLayout>

[Edit] I didn't find the root cause. But the following works:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_widget" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:background="@drawable/background">

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"
    android:id="@+id/title_bar" >

    <include layout="@layout/title_bar" />
</RelativeLayout>

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"
    android:id="@+id/navigation_bar" >

    <include layout="@layout/navigation_bar" />
 </RelativeLayout>

解决方案

In order to override the attributes of the layout you're including, you must also override both the layout width and layout height. If both of those settings are not overridden, any other layout changes you try will be ignored.

Your layout above

<include android:id="@+id/title_bar" layout="@layout/title_bar" 
    android:layout_alignParentTop="true"
/>
<include android:id="@+id/navigation_bar" layout="@layout/navigation_bar" 
    android:layout_alignParentBottom="true"/>

Should actually be with a wrap content or fill parent, as appropriate.

<include android:id="@+id/navigation_bar" layout="@layout/navigation_bar"  android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>

这篇关于有什么毛病我包括RelativeLayout的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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