1

Issue :Give elevation for an image in my layout.
Layout Structure: Constraint Layout-> Card View
The image to be elevated in half on constraint layout and half on card view. I could not use the shadow approach since my image is not completely on a single view.

Is there a way this is possible on pre-lollipop devices?

Layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:background="#246389"
    android:orientation="vertical">

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/imageView3"
        android:layout_width="264dp"
        android:layout_height="152dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:elevation="12dp"        
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@drawable/login_car" />

    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="270dp"
        android:layout_height="450dp"
        android:layout_margin="20dp"
        app:cardBackgroundColor="#00AFEF"
        app:cardUseCompatPadding="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintLeft_toRightOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        app:layout_constraintVertical_bias="0.5">                
    </android.support.v7.widget.CardView>    
</android.support.constraint.ConstraintLayout>

Screen

Mitali Bhokare
  • 177
  • 1
  • 2
  • 11

1 Answers1

0

I imitated a CardView with general android layouts and custom background. Then in parent FrameLayout it is easy to add one element above another

dialog_layout

<layout 
    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">

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/base_transparent">

            <FrameLayout
                android:layout_width="300dp"
                android:layout_height="210dp"
                android:background="@drawable/bg_dialog">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="90dp"
                    android:background="@drawable/bg_dialog_upper_radius"
                    android:orientation="vertical">

                    <TextView
                        style="@style/AppTheme.PaymentContentTextAppearanceName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="16dp"
                        android:text="@string/payment_view_main_account" />

                    <TextView
                        android:id="@+id/tv_total_payment"
                        style="@style/AppTheme.PaymentView.Summ"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginBottom="16dp"
                        tools:text="80000" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="10dp"
                    android:orientation="horizontal">

                    <com.bifit.mobile.lite.std.ui.customview.CompatTextView
                        android:id="@+id/send_payment_email"
                        style="@style/AppTheme.BottomButton"
                        android:text="@string/payment_view_send_email"
                        android:textColor="@color/base_blue"
                        app:drawableTopCompat="@drawable/ic_message_send" />

                    <com.bifit.mobile.lite.std.ui.customview.CompatTextView
                        android:id="@+id/save_pdf_payment"
                        style="@style/AppTheme.BottomButton"
                        android:text="@string/payment_view_save_pdf"
                        android:textColor="@color/base_blue"
                        app:drawableTopCompat="@drawable/ic_save_pdf" />

                </LinearLayout>
            </FrameLayout>

            <ImageButton
                android:id="@+id/ib_okay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="170dp"
                android:background="@drawable/bg_blue_circle"
                android:clickable="true"
                android:focusable="true"
                app:srcCompat="@drawable/ic_check" />

        </FrameLayout>
</layout>

bg_dialog_upper_radius

<layer-list 
xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
          <shape android:shape="rectangle">
              <solid android:color="@color/base_gray_light_second"/>
              <corners
                  android:topLeftRadius="10dp"
                  android:topRightRadius="10dp"
                  />
          </shape>
      </item>
 </layer-list>

And the result

NovDanil
  • 51
  • 8