首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >How to make CardView overlap

How to make CardView overlap
EN

Stack Overflow用户
提问于 2017-11-21 22:02:28
回答 2查看 3.2K关注 0票数 2

我已经尝试完成类似于以下布局的事情。

有几件事需要注意。覆盖appbar的cardview不应该是nestedscrollview的一部分,因为我在xml布局中有一个nestedscrollview。cardview的位置是正确的,但它恰好位于appbarlayout的下方。

EN

回答 2

Stack Overflow用户

发布于 2017-11-23 05:06:04

我现在才找到解决这个问题的办法。我之前没有给CardView一个高程值,这是错误的。我只是认为让它在CoordinatorLayout中最后出现应该把它放在最上面。它现在起作用了。我已经添加了一个高程值。这是代码-

代码语言:javascript
复制
<xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbarlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/quotes"
                android:scaleType="centerCrop"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/tool"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="parallax"/>


        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>



    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorWhite"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginRight="32dp"
        android:layout_marginLeft="32dp"
        app:layout_anchor="@id/appBar"
        app:layout_anchorGravity="bottom|center"
        app:cardElevation="@dimen/small_padding"
        />

</android.support.design.widget.CoordinatorLayout>
票数 3
EN

Stack Overflow用户

发布于 2017-11-23 00:17:18

尝试使用以下布局。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@color/colorAccent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways"
        app:layout_collapseMode="pin">

        <ImageView
            android:id="@+id/toolbar_logo"
            android:src="@drawable/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"/>

    </android.support.v7.widget.Toolbar>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginLeft="45dp"
        android:layout_marginRight="45dp"
        app:cardCornerRadius="8dp"
        app:cardElevation="7dp"
        android:layout_marginTop="150dp"
        android:id="@+id/cardView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Photos" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="376" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_weight="1">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Followers"
                    android:layout_gravity="center"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1769"
                    android:layout_gravity="center"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_weight="1">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Following"
                    android:layout_gravity="center"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="127"
                    android:layout_gravity="center"/>
            </LinearLayout>

        </LinearLayout>
    </android.support.v7.widget.CardView>

</RelativeLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47414969

复制
相关文章

相似问题

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