安卓剪辑儿童不工作角落半径形状



我在裁剪约束布局视图时遇到问题。

这是我的 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/deck_card_corner_radius"
android:clipChildren="true"
>
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleType="centerCrop"
app:srcCompat="@drawable/splashscreen" />
</android.support.constraint.ConstraintLayout>

deck_card_corner_radius

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="270" android:endColor="#316db2" android:startColor="#316db2" />
<corners android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp" android:topLeftRadius="30dp" android:topRightRadius="30dp"/>
</shape>

没有图像我得到了这个

无图像源

带图像

不剪角

有人可以帮助我吗?

使用CardView怎么样?

我不认为设置圆形背景实际上会"塑造"视图半径。它仍然是一个带有锋利边缘的矩形,只是在其中渲染圆形背景。您可以通过查看布局编辑器来查看这一点。如果单击视图,即使设置了圆角背景,您也知道它实际上不是圆形的。

我一直在使用CardView,它运行良好。

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardPreventCornerOverlap="false"
app:cardCornerRadius="4dp"
app:cardUseCompatPadding="true">
<!-- Content goes here i.e. ImageView, ConstraintLayout, etc... -->
</android.support.v7.widget.CardView>

这里最重要的是app:cardPreventCornerOverlap=false.它剪辑内容,使其可以平滑地适应容器视图,而无需任何不必要的填充。文档在这里。

最新更新