简体   繁体   中英

Add shadow between layout

I'm trying to do this for months and finally i can't find anyway. Elevation is just for API 21+ and other ways sometimes work and sometimes doesn't. I'm working on a music player and i need shadow between music controller and musics cover. How to add shadow? elevation doesn't work here as you can see

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ImageView
        android:id="@+id/now.playing.cover"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:scaleType="centerInside"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:padding="8dp">

        <TextView
            android:id="@+id/now.title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:textColor="@color/colorSecondaryText" />

        <TextView
            android:id="@+id/now.artist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:textColor="@color/colorSecondaryText" />

        <TextView
            android:id="@+id/now.album"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:textColor="@color/colorSecondaryText" />

        <android.support.v7.widget.AppCompatSeekBar
            android:id="@+id/now.seek"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:paddingLeft="32dp"
            android:layout_marginTop="8dp"
            android:paddingRight="32dp">

            <ImageView
                android:id="@+id/prev"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:layout_marginRight="56dp"
                android:padding="2dp"
                android:src="@drawable/prev" />

            <ImageView
                android:id="@+id/pp"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:layout_marginRight="56dp"
                android:padding="2dp"
                android:src="@drawable/play" />

            <ImageView
                android:id="@+id/next"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:padding="2dp"
                android:src="@drawable/next" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

在此处输入图片说明

You can add a view in between which looks like shadow.. Below is an example of same which I have used and it almost works on all the apis.. May be it can help you..

Shadow View:

 <View
        android:id="@+id/toolbar_shadow"
        android:layout_width="match_parent"
        android:layout_height="15dp"
        android:layout_below="@+id/toolbar"
        android:background="@drawable/toolbar_shadow" />

And the drawable file:

<?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="#88444444"
        android:startColor="#00000000" />
</shape>

看起来像这样

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM