有什么毛病我包括RelativeLayout的?有什么、毛病、RelativeLayout

由网友(深愛是致命的痛)分享简介:我想创建一个在顶部标题栏和底部的导航栏中选择一个活动。我用包括包括标题栏布局和导航栏布局到主布局正如你可以看到下面。其结果是,无论是标题栏和导航条转到屏幕的顶部。有人能告诉我为什么吗?谢谢!< XML版本=1.0编码=UTF-8&GT?;< RelativeLayout的的xmlns:机器人=htt​​p...

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

 < 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的>
 

解决方案 Android 开发RelativeLayout与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"/>

阅读全文

相关推荐

最新文章