首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓clipChildren不工作cornerRadius形状

安卓clipChildren不工作cornerRadius形状
EN

Stack Overflow用户
提问于 2018-07-10 05:10:04
回答 1查看 2K关注 0票数 3

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

这是我的xml布局代码

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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

有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-10 05:52:51

使用CardView怎么样?

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

我一直在使用CardView来做这件事,它工作得很好。

代码语言:javascript
复制
<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.它剪辑内容,以便它可以流畅地适合容器视图,而不需要任何不必要的填充。文档是here

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51254077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档