代码之家  ›  专栏  ›  技术社区  ›  mducc

立面在约束布局中不起作用

  •  1
  • mducc  · 技术社区  · 7 年前

    我不知道为什么 android:elevation 不起作用

    <android.support.constraint.ConstraintLayout 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:background="@color/colorWhite"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context=".UI.Activity.ChatActivity">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:elevation="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_default="percent"
            app:layout_constraintHeight_percent="0.07"
            app:layout_constraintStart_toStartOf="parent"
            android:gravity="center_vertical">
    
            <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="8"
                android:inputType="text"
                android:layout_marginLeft="15dp"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="5dp"
                android:background="@drawable/border_edit_text_messenger"
                android:textCursorDrawable="@color/colorWhite"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"/>
    
            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.8"
                android:src="@drawable/ic_send"
                android:scaleType="centerInside"
                android:layout_marginRight="15dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"/>
        </LinearLayout>
    
    </android.support.constraint.ConstraintLayout>
    
    2 回复  |  直到 7 年前
        1
  •  16
  •   Pankaj Kumar    7 年前

    在将任何背景色设置为 ViewGroup View 要在其中设置高程的。

    android:background="@color/colorWhite"
    android:elevation="2dp"
    

    在上面的xml中进行线性布局。

        2
  •  8
  •   Community Mohan Dere    6 年前

    有背景的 ,所以会有 没有阴影 对于 没有背景 .

    • 或者给你的视图设置一个背景。
    • android:outlineProvider="bounds" .

    建议:

    以上两种解决方案都适用于Android版本>21

    所有版本的解决方案

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent="0.07"
        app:layout_constraintStart_toStartOf="parent"
        >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            >
    
        </LinearLayout>
    
        <View
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:background="@drawable/shadow"/>
    
    </FrameLayout>
    

    显示.xml 可拉伸的

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

    output

    你可以找到很多方法来添加阴影 here .

        3
  •  0
  •   android_dev71    6 年前

    android:layout_margin="5dp"
    app:cardElevation="8dp"
    

    我有一张约束图里面的材料卡片的要点 here 如果没有它 here

    如果对你也有用,请告诉我。