0

This is the what my activity currently looks like.

enter image description here

I am able to elevate the first two CardView but for the bottom one it is not elevated. I have tried both app:cardElevation and android:elevation but none of the elevates the last card. (by the way what's the difference of these two?)

How can I elevate it?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/ef_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/colorBackgroundFloating"
            android:elevation="2dp"
            app:contentInsetStart="0dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageButton
                    android:id="@+id/cancel_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:background="@android:color/transparent"
                    android:src="@drawable/ic_cancel"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <ImageButton
                    android:id="@+id/confirm_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:background="@android:color/transparent"
                    android:src="@drawable/ic_confirm"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.Toolbar>

        <android.support.v7.widget.CardView
            android:id="@+id/food_image_card"
            android:layout_width="180dp"
            android:layout_height="180dp"
            android:layout_marginStart="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="20dp"
            app:cardElevation="2dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/ef_toolbar">
            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/food_image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/food_image_place_holder" />

                <ImageButton
                    android:id="@+id/camera_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:srcCompat="@drawable/ic_camera" />
            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/food_name_card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            app:cardElevation="2dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/food_image_card">
            <EditText
                android:id="@+id/edit_food_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:ems="10"
                android:hint="Food Name"
                android:background="@null"
                android:maxLength="50"
                android:maxLines="1"
                android:inputType="textPersonName"
                android:importantForAutofill="no" />
        </android.support.v7.widget.CardView>

        <TextView
            android:id="@+id/tags_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:text="Tags"
            android:textSize="16sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/food_name_card_view" />

        <ImageButton
            android:id="@+id/add_tag_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:background="@android:color/transparent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@+id/tags_text"
            app:srcCompat="@drawable/ic_add_dark" />

        <android.support.v7.widget.CardView
            android:id="@+id/tag_card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:minHeight="120dp"
            app:cardElevation="2dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tags_text">

            <FrameLayout
                android:id="@+id/tags_frame"
                android:layout_margin="4dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </android.support.v7.widget.CardView>

        <TextView
            android:id="@+id/food_note"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:text="Note"
            android:textSize="16sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tag_card_view" />

        <android.support.v7.widget.CardView
            android:id="@+id/food_note_card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            app:cardElevation="2dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/food_note">

            <EditText
                android:id="@+id/edit_note"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:ems="10"
                android:textSize="16sp"
                android:background="@null"
                android:minHeight="200dp"
                android:gravity="start|top"
                android:inputType="textMultiLine"
                android:singleLine="false" />
        </android.support.v7.widget.CardView>
    </android.support.constraint.ConstraintLayout>
</ScrollView>
Seaky Lone
  • 992
  • 1
  • 10
  • 29

3 Answers3

1

add

Margin bottom = 10dp to this cardview

android:id="@+id/food_note_card_view"

Peter Alwin
  • 239
  • 1
  • 6
0

This can be helpful

app:cardUseCompatPadding="true"

See the Below example

 <androidx.cardview.widget.CardView
    app:cardBackgroundColor="#FF0000"
    app:cardElevation="2dp"
    app:cardUseCompatPadding="true"
    android:layout_width="match_parent"
    android:layout_height="200dp"/>
Android Dev
  • 1,496
  • 1
  • 13
  • 25
0

Cardview not working properly inside Cardview.

Please try to place your cardview into another layout such as FrameLayout or RelativeLayout.

Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159