嗨,我有两个cardviews,每个都包装在一个相对布局中,并使用了layout_below属性,但是它似乎不起作用,下面的所有代码都包装在一个framelayout中,不确定这是否会是一个问题。我已经尝试将布局更改为线性,这是可行的,但我希望有一个相对的布局。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/breakfast_view">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/breakfast_card"
android:layout_width="match_parent"
android:layout_height="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/info_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Breakfast"
android:paddingBottom="5dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/breakfast_view">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/overview"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp"
card_view:cardCornerRadius="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<View
android:id="@+id/info_spliter"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#E0E0E0"
android:layout_below="@+id/info_tester"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>发布于 2016-02-19 21:42:46
您为info_splitter的layout_below引用的id info_tester未定义。即使定义了它,也只能在同一个RelativeLayout元素中引用同级元素。也就是说,您的CardView元素或您希望相对定位的任何其他元素应该驻留在相同的RelativeLayout元素中,以便您能够使用layout_below将它们相对于彼此进行定位。
发布于 2016-02-19 21:50:47
正如您所说的,您正在使用框架布局,这就是问题所在,因为框架布局中的每个根元素都被视为一个单独的框架,因此请尝试使用相对布局作为父级,如下所示,或者在框架布局中使用单个子级,然后在子级中添加视图
<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"
tools:context=".AudioPlayerFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/breakfast_view">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/breakfast_card"
android:layout_width="match_parent"
android:layout_height="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/info_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Breakfast"
android:paddingBottom="5dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/breakfast_view">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/overview"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10dp"
card_view:cardCornerRadius="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<View
android:id="@+id/info_spliter"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#E0E0E0" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</RelativeLayout>https://stackoverflow.com/questions/35506351
复制相似问题