提升前棒棒糖设备中的图像(< 21)

时间:2017-08-04 16:57:24

标签: android-layout backwards-compatibility android-elevation

问题:为我的布局中的图像提供高程。
布局结构:约束布局 - >卡片视图
图像在约束布局上升高一半,在卡片视图上升高一半。 我不能使用阴影方法,因为我的图像不完全在一个视图上。

预先棒棒糖设备有可能实现这一目标吗?

布局文件:

<?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

1 个答案:

答案 0 :(得分:0)

我模仿了CardView,它具有一般的android布局和自定义背景。然后在父级FrameLayout中,很容易在另一个元素上方添加一个元素

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>

还有the result