android clipChildren 不工作角半径形状

标签 android xml clip cornerradius

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

这是我的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>

没有图像我得到了这个

no image src

有图片

not clipping corner

谁能帮帮我?

最佳答案

使用 CardView 怎么样?

我不认为设置圆形背景实际上“塑造”了视野半径。它仍然是一个带有锐边的矩形,只是在其中渲染了圆形背景。您可以通过查看布局编辑器来检查这一点。如果您单击该 View ,您就会知道即使在设置了圆形背景之后它实际上也不是圆形的。

为此,我一直在使用 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。它裁剪内容,以便它可以平滑地适应容器 View ,而无需任何不必要的填充。文档是 here .

关于android clipChildren 不工作角半径形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51254077/

相关文章:

android - 我无法在 Android 的 webview 上显示本地 html 文件

android:textColor 实际上没有工作

r - 在 R 中与轮廓和多边形相交

xml - 从 XML 文件生成类图的免费插件?

xml - 使用 Oracle XMLType 时处理空值

css - 修复剪辑路径或 mask 的位置

html - 伪元素影响剪辑路径

android - 谷歌广告系列测量跟踪

Android 相当于 iOS 的 UILocalNotification

android - Android平台使用次数