Как добиться тени над картой? - PullRequest
1 голос
/ 01 апреля 2020

Я пытаюсь добиться следующего макета:

enter image description here

  1. Я хочу расширить каждое представление при нажатии.
  2. Как получить тень для каждого вида?

Я пробовал следующую схему рисования:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

  <item>
    <shape android:shape="rectangle">

      <gradient
          android:startColor="#cacaca"
          android:centerColor="#b6b6b6"
          android:endColor="#e9e9e9"
          />
    </shape>

    <gradient
        android:startColor="#6586F0"
        android:centerColor="#D6D6D6"
        android:endColor="#4B6CD6"
        android:angle="90"/>
  </item>

  <item
      android:left="0dp"
      android:right="0dp"
      android:top="5dp"
      android:bottom="2dp">
    <shape android:shape="rectangle">
      <solid android:color="#ffffff"/>
      <corners android:radius="20dp"/>
    </shape>
  </item>
</layer-list>

Но она показывает следующий вид:

enter image description here

Пожалуйста, помогите мне добиться правильного вида.

Ответы [ 2 ]

0 голосов
/ 03 апреля 2020

Попробуйте следующий код:

Для рисования:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Drop Shadow Stack -->
    <item>
        <shape android:shape="rectangle">
            <padding
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />
            <corners android:topLeftRadius="20dp"
                android:topRightRadius="20dp"/>
            <solid android:color="#14000029" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <padding
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />
            <corners android:topLeftRadius="20dp"
                android:topRightRadius="20dp"/>
            <solid android:color="#14000029" />
        </shape>
    </item>
    <item>
        <shape
            android:shape="rectangle">
            <padding
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <corners android:topLeftRadius="20dp"
                android:topRightRadius="20dp"/>
            <solid android:color="#14000029" />
        </shape>
    </item>
    <!-- Background -->
    <item>
        <shape
            android:shape="rectangle">
            <corners android:topLeftRadius="20dp"
                android:topRightRadius="20dp"/>
            <solid android:color="@android:color/white"/>
        </shape>
    </item>
</layer-list>

Код в файле макета

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CardViewShadowActivity"
    android:layout_marginTop="30dp">
    <LinearLayout
        android:id="@+id/linear_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="10dp"
        android:paddingBottom="30dp"
        android:background="@drawable/custom_bg">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/linear_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="10dp"
        android:paddingBottom="30dp"
        android:background="@drawable/custom_bg"
        android:layout_below="@id/linear_1"
        android:layout_marginTop="-20dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/linear_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="10dp"
        android:paddingBottom="30dp"
        android:background="@drawable/custom_bg"
        android:layout_below="@id/linear_2"
        android:layout_marginTop="-20dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/linear_4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="10dp"
        android:paddingBottom="30dp"
        android:background="@drawable/custom_bg"
        android:layout_below="@id/linear_3"
        android:layout_marginTop="-20dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello"/>
    </LinearLayout>
</RelativeLayout>

Настроить макет и рисовать в соответствии с вашими потребностями.

Выход для вышеуказанного кода:

enter image description here

Надеюсь, это поможет вам

0 голосов
/ 01 апреля 2020

вы можете достичь этого, вложив несколько cardViews в FrameLayout. Измените свойства android:layout_marginTop и app:cardElevation, чтобы придать стеку эффект.

...