【发布时间】:2018-04-16 06:58:43
【问题描述】:
编辑:这里建议的解决方案让我可以自己绘制阴影。一世 不希望这样,因为视图将被动画化(translationZ 会改变 随着时间的推移),我想避免自己渲染阴影 在动画期间。我想要帮助的一些解决方案 android-system 将我的形状识别为高程的背景。 如果找不到这样的解决方案,那么困难的方法将是子类化 ViewOutlineProvider 带有凸路径,但我真的很想避免 这个。
正如问题的名称所暗示的那样,我在让 android 的高度与不同圆角的矩形一起工作时遇到问题。 (在问题末尾添加图片)
当只有 1 个默认半径时它确实有效,即在这个例子中:
rounded_rect.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/holo_orange_dark"/>
<corners android:radius="5dp"/>
</shape>
activity.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/rounded_rect"
android:elevation="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
但是当我将 rounded_rect.xml 更改为以下代码时,不会投射任何阴影:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/holo_orange_dark"/>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="10dp"
android:topRightRadius="30dp"
/>
</shape>
我尝试在 rounded_rect.xml 的 <corners> 标记中添加 android:radius="5dp",但没有添加阴影。
任何帮助将不胜感激!
【问题讨论】:
标签: android xml android-layout