首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CardView相互重叠

CardView相互重叠
EN

Stack Overflow用户
提问于 2016-02-19 21:20:54
回答 2查看 2.2K关注 0票数 1

嗨,我有两个cardviews,每个都包装在一个相对布局中,并使用了layout_below属性,但是它似乎不起作用,下面的所有代码都包装在一个framelayout中,不确定这是否会是一个问题。我已经尝试将布局更改为线性,这是可行的,但我希望有一个相对的布局。

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2016-02-19 21:42:46

您为info_splitterlayout_below引用的id info_tester未定义。即使定义了它,也只能在同一个RelativeLayout元素中引用同级元素。也就是说,您的CardView元素或您希望相对定位的任何其他元素应该驻留在相同的RelativeLayout元素中,以便您能够使用layout_below将它们相对于彼此进行定位。

票数 0
EN

Stack Overflow用户

发布于 2016-02-19 21:50:47

正如您所说的,您正在使用框架布局,这就是问题所在,因为框架布局中的每个根元素都被视为一个单独的框架,因此请尝试使用相对布局作为父级,如下所示,或者在框架布局中使用单个子级,然后在子级中添加视图

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35506351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档