gpt4 book ai didi

java - ImageView 圆角

转载 作者:IT老高 更新时间:2023-10-28 21:06:58 30 4
gpt4 key购买 nike

我希望图像具有圆角。我实现了这个 xml 代码并在我的 ImageView 中使用它。但图像与形状重叠。我正在通过异步任务下载图像。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="20dip" />
</shape>


<ImageView
android:id="@+id/trVouchersImage"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_alignParentLeft="true"
android:background="@drawable/ash_arrow"
/>

最佳答案

最简单的方法:

在您应用的 res/drawable/ 文件夹下创建一个 xml 文件 rounded_fg.xmlrounded_fg.xml的内容如下,

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2"
android:shape="ring"
android:thicknessRatio="1"
android:useLevel="false">
<gradient
android:type="radial"
android:gradientRadius="8dp"
android:endColor="@color/white"
/>
</shape>

您可以将 endColor 与 ImageView 容器布局背景匹配 & gradientRadius 可以根据您的要求为任何值 (<=36dp)。

现在将此可绘制对象用作您的 ImageView 的 前景,如下所示,

 <ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:foreground="@drawable/rounded_fg" />

完美搭配方形图像和/或 ImageView

方形图像/ImageView:

Square Image/ImageView

矩形图像/ImageView:

Rectangular Image/ImageView

在按钮上应用前景:

Foreground applied over a button

关于java - ImageView 圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20743859/

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