Casting a shadow without transparency

In this project (feature / drop-shadow branch) I am trying to add a drop shadow above the view container. So I defined the following shape ( drawable / shadow_above ):

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

      

This is then used in the layout file ( container_infos.xml ) like this:

<View
    android:background="@drawable/shadow_above"
    android:layout_width="match_parent"
    android:layout_height="4dp"/>

      

The screenshot shows the result. For some reason, the shadow looks terrible. no transparency . What am I doing wrong? Feel free to submit a pull request to my open source project.

Awful drop shadow


Solution using RelativeLayout

I was able to get the desired output using RelativeLayout in the fragment_map.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              tools:context=".ui.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <FrameLayout
            android:id="@+id/map_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:background="@android:color/holo_purple"/>

        <View
            android:background="@drawable/shadow_above"
            android:layout_alignBottom="@id/map_container"
            android:layout_width="match_parent"
            android:layout_height="4dp"/>

    </RelativeLayout>

    <include
        layout="@layout/container_infos"/>

</LinearLayout>

      

There may be room for optimization.

+3


source to share


1 answer


as far as i can see you should give map_container_infos_layout a negative top edge of the 4dp size and it should look better



0


source







All Articles