gpt4 book ai didi

android clipChildren 不工作角半径形状

转载 作者:行者123 更新时间:2023-11-29 23:46:54 25 4
gpt4 key购买 nike

我在裁剪约束布局 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com