1

I am writing a code with a few nested layouts. As I have used material design I also wanted to set elevation. Though elevation was working fine with the elements of outermost layout, the contents of the inner LinearLayout (nested inside a CoordinatorLayout) is not casting shadows despite setting elevation.

<?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"
    android:background="@color/white"
    tools:context="com.joblesscoders.aditya.todolist.HomeActivity">

    <TextView
        android:layout_width="match_parent"
        android:id="@+id/count"
        android:text="Main Activity"
        android:textSize="20dp"
        android:elevation="5dp"
        android:textColor="@color/white"
        android:gravity="center_vertical"
        android:background="@color/colorPrimary"
        android:layout_height="50dp" />


    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/cly"
        android:background="@color/white"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        >
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/sv"
            android:background="@color/white"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/lly"
                android:background="@color/white"
                android:orientation="vertical">

                <TextView
                    android:text="Task here"
                    android:id="@+id/tid"
                    android:textSize="40sp"
                    android:layout_marginBottom="5dp"
                    android:layout_width="match_parent"
                    android:elevation="4dp"
                    android:paddingBottom="10dp"
                    android:paddingTop="10dp"
                    android:layout_height="wrap_content" />
                <TextView
                    android:text="Task here"
                    android:id="@+id/tid"
                    android:textSize="40sp"
                    android:layout_marginBottom="5dp"
                    android:layout_width="match_parent"
                    android:elevation="4dp"
                    android:paddingBottom="10dp"
                    android:paddingTop="10dp"
                    android:layout_height="wrap_content" />
                <TextView
                    android:text="Task here"
                    android:id="@+id/tid"
                    android:textSize="40sp"
                    android:layout_marginBottom="5dp"
                    android:layout_width="match_parent"
                    android:elevation="4dp"
                    android:paddingBottom="10dp"
                    android:paddingTop="10dp"
                    android:layout_height="wrap_content" />
                <!-- More TextViews to suit purpose -->


            </LinearLayout>
        </ScrollView>
        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:src="@drawable/ic_add2"
            app:rippleColor="@color/white"
            android:id="@+id/fab"
            android:layout_gravity="bottom|end"
            />
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

This code in android studio designer view produces the expected result i.e. Screenshot 1

the TextViews displaying "Task here" have required shadows, but as soon I run it on a android 6.O custom device, the page becomes: Screenshot 2

I would be thankful if anybody corrects me or advices on the dos and don'ts. I am extremely new to android programming, and this is my first code. So please bear with me if I have made any really very silly mistake.

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64

0 Answers0