recyclerview中的Cardview与折叠工具栏重叠

时间:2016-01-15 20:44:35

标签: android android-recyclerview android-cardview

我正在尝试在collalering工具栏下面创建一个recyclelerview,其中包含了在recyclerview中的cardview。如何克服在recyclerview内部充满cardview的重叠。它与折叠的工具栏图像重叠。

xml文件

 <?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

     <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true"
            >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"
                />

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

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




    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rv"
        android:orientation="vertical"
        android:clipToPadding="false"
        android:layout_marginTop="?attr/actionBarSize"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@+id/image"
        />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        app:layout_anchor="@id/app_bar_layout"
        style="@style/fab"
        app:theme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_anchorGravity="bottom|right|end"
        />




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

在recyclerview内部充气的项目

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.co nbm/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dp"
    app:cardElevation="6dp"
    android:padding="6dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:id="@+id/cv">

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.co nbm/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff">




        <com.github.siyamed.shapeimageview.CircularImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:scaleType="centerCrop"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:layout_margin="16dp"
            android:layout_gravity="center"
            android:src="@drawable/li"
            android:id="@+id/imageView"
            app:siBorderWidth="6dp"
            app:siBorderColor="@color/secondary_text"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView"
            android:text="Aayush Chaubey"
            android:paddingTop="16dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/imageView"
            android:textColor="#000000"
            android:textSize="20sp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:text="app developer"
            android:textColor="#000000"
            android:textSize="15sp"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/textView"
            android:layout_alignStart="@+id/textView" />




    </RelativeLayout>


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

2 个答案:

答案 0 :(得分:4)

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/app_bar_layout"
        android:clipToPadding="false"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/app_bar_layout"
        app:layout_anchorGravity="bottom|right|end"
        app:theme="@style/ThemeOverlay.AppCompat.Light" />


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

看看,尤其是:

https://github.com/liuguangqiang/AndroidDesignSupportSample

这个布局: https://github.com/liuguangqiang/AndroidDesignSupportSample/blob/master/app/src/main/res/layout/activity_detail.xml

答案 1 :(得分:1)

在你的第一个布局文件中,放置recylerview AppBarLayout的底部:

<button type="button" style="margin-bottom: 5px;" class="btn btn-danger btn-default btn-gray btn-primary btn-primary2 btn-success2 btn-warning btn-black btn-success btn_bottom_padding" data-toggle="modal" data-target="#myModal" data-bind="css: {'btn-gray': IsGray(), 'btn-danger': IsRed(),'btn-success':IsGreen(), 'btn-primary': IsBlue(),'btn-success2':IsLimegreen(), 'btn-primary2': IsSkyblue(),'btn-warning':IsOrange(),'btn-black': IsBlack(),'btn-default':IsWhite()},click:$root.GetClick">
   <span data-bind="text:ShortName()"></span>
   <span data-bind="visible: IsRed()" class="fa fa-exclamation-triangle"></span>
   @*<span data-bind="" class="fa fa-bolt"></span>*@
</button>

而不是:

 android:layout_below="@+id/app_bar_layout"