RecyclerView重叠而没有阴影 [英] RecyclerView overlapping without shadow

查看:88
本文介绍了RecyclerView重叠而没有阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发像这张照片一样的列表

I want to develop List like this picture

我曾经对RecylerView ItemDecorator进行过重叠.但是它是重叠的,没有阴影.屏幕和装饰器代码如下

I had used to RecylerView ItemDecorator for overlap. But it's overlapping without shadow. the screen & decorator code is below

public class OverlapDecoration extends RecyclerView.ItemDecoration {

private final static int vertOverlap = -50;

@Override
public void getItemOffsets (Rect outRect, View view, RecyclerView parent,       RecyclerView.State state) {

outRect.set(0, 0, 0, vertOverlap);
}
}

card_layout.xml

card_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="cards main container">

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="@color/color_white"
    card_view:cardElevation="5dp"
    card_view:cardUseCompatPadding="true">

            <TextView
                android:id="@+id/textViewName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:layout_marginBottom="30dp"
                android:text="Android Name"
                android:textAppearance="?android:attr/textAppearanceLarge"/>

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

</LinearLayout>

推荐答案

尝试此代码

card_layout.xml

card_layout.xml

<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="wrap_content"
    android:orientation="vertical"
    android:tag="cards main container">

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp"
        android:clipToPadding="false"
        android:elevation="0dp"
        card_view:cardUseCompatPadding="false"
        card_view:paddingEnd="0dp"
        card_view:paddingStart="0dp">

        <TextView
            android:id="@+id/textViewName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="30dp"
            android:layout_marginTop="30dp"
            android:gravity="center"
            android:text="Android Name"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_above="@id/textViewName"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/card_shadow" />
    </android.support.v7.widget.CardView>


</RelativeLayout>

卡阴影 card_shadow

for card shadow card_shadow

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:endColor="#77111111"
        android:startColor="@android:color/transparent" />
</shape>

这篇关于RecyclerView重叠而没有阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆