我不知道为什么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>
Run Code Online (Sandbox Code Playgroud)
Pan*_*mar 18
不知何故,在您为要设置高程的ViewGroup或设置任何背景颜色之前,高程不起作用View。
放
android:background="@color/colorWhite"
android:elevation="2dp"
Run Code Online (Sandbox Code Playgroud)
到上面 xml 中的 LinearLayout。
这是默认行为阴影一些背景标识,所以会有没有影子的没有背景。
android:outlineProvider="bounds"。以上两种解决方案都适用于 >21 的 Android 版本。
所有版本的解决方案
您可以在视图上放置可绘制的阴影。
<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>
Run Code Online (Sandbox Code Playgroud)
将showdow.xml放入 drawable
<?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>
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到许多添加阴影的方法。
| 归档时间: |
|
| 查看次数: |
7056 次 |
| 最近记录: |