RelativeLayout+include嵌套布局有问题。

ihrthk
博客专家认证
2012-12-11 11:14:12
activity_main.xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/txt_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="标题"
android:textSize="32dip" />

<include
android:layout_below="@+id/txt_title"
layout="@layout/part" />

</RelativeLayout>


part.xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/txt_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="具体内容" />

</RelativeLayout>


显示效果如下:


我想要的是part整个布局在txt_title下面,请问这个是怎么回事?

...全文
271 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ihrthk 2012-12-12
  • 打赏
  • 举报
回复
谢谢各位,我明白了。
  • 打赏
  • 举报
回复
android:layout_below="@+id/txt_title" 这个对include无效的,要打到这个效果,需要加一个布局。比如: <RelativeLayout android:layout_below="@+id/txt_title" android:layout_width="match_parent" android:layout_height="wrap_content" > <include layout="@layout/part" /> </RelativeLayout>
香_菇 2012-12-12
  • 打赏
  • 举报
回复
学习了
80后VS烦恼 2012-12-12
  • 打赏
  • 举报
回复
android:layout_below="@+id/txt_title" 应改为android:layout_below="@id/txt_title"
qinjuning 2012-12-12
  • 打赏
  • 举报
回复
顶 2L 、 3L 。 解析时,只会解析 <include android:layout_weight android:layout_height android:id>这三个Attribute 其他的貌似都不会解析了,也就是无效。
顾小林 2012-12-12
  • 打赏
  • 举报
回复
android:layout_below="@id/txt_title" "@+id/txt_title” 是定义ID 给分
dong3560 2012-12-12
  • 打赏
  • 举报
回复
在include标签里面按ALT+/,出来的就是支持的属性 其他属性写上去不会报错,但也不会生效
wlcw16 2012-12-11
  • 打赏
  • 举报
回复
android:layout_below="@+id/txt_title" 意思就是在 txt_title下面

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧