我正在尝试找出一种方法,使布局中的项目与包含的布局中的项目对齐。
这是一个视觉表示:
这是我正在寻找的示例代码(显然不起作用):
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/