android - 包含布局内的 layout_below 项

标签 android android-layout android-relativelayout

我正在尝试找出一种方法,使布局中的项目与包含的布局中的项目对齐。

这是一个视觉表示: enter image description here

这是我正在寻找的示例代码(显然不起作用):
Main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <include
        android:id="@+id/info"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/info" />
    //This would be the dark grey box
    <RelativeLayout
        android:layout_below="@id/item1">
    </RelativeLayout>
</RelativeLayout>

included.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dp">
    <ImageView
        android:id="@+id/item1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:paddingLeft="100dp"/>
</RelativeLayout>



我假设实现此目的的最佳方法是通过在代码中动态定位深灰色框,但我不知道从哪里开始。任何帮助都会很棒。

最佳答案

你能把这个放在你的包含下面吗?像这样的东西(而不是 item1 使用信息):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <include
        android:id="@+id/info"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/info" />
    //This would be the dark grey box
    <RelativeLayout
        android:layout_below="@id/info">
    </RelativeLayout>
</RelativeLayout>

关于android - 包含布局内的 layout_below 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12599861/

相关文章:

android - 如何重组布局以使其更好?

android - 自定义 RelativeLayout 中缺少 View

android - 如何创建正方形布局并将其水平居中

android - AS3 mp3 数组中的对象并检索和播放它们请帮助 AS3 新手

android - 如何自动缩放 OpenGL ES 2.0 窗口?

javascript - 如何防止android表单跳过表单中的部分?

android - 线性布局中的 ImageView

android - 如何在 .NET 上序列化和在 WP、Win8、iOS 和 Android 上反序列化并保留引用

android - 当项目有复选框时,RecyclerView 项目不显示涟漪/触摸反馈

Android,layout_above 不工作