如何在 android 中将圆形图像视图背景设置为黑色?

How to set Circular Image View Background black in android?

图片视图背景只反映在圈内,不反映在圈外。 我尝试了很多东西,但做不到。 任何人请我。 谢谢!!

在 drawable 文件夹中创建一个 .xml 文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<shape
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="oval">
     <solid
        android:color="@color/black"/>
</shape>

然后将此文件设置为您的背景。

我猜您正在使用 CircularImageView 自定义图像视图 class 使其成为圆形。这就是为什么它只在特定区域应用的背景。

要解决它,请执行以下操作,

<LineaLayout
     android:width="wrap_content"
     android:height="wrap_content"
     android:orientation="vertical"
     android:background="@color/black"/>


<!-- your circular CircularImageView here..!! -->

</LinearLayout>

您可以做的其他解决方案是,使用原生 ImageView 并通过创建循环 bitmap 设置其 android:src 并使用 android:background 黑色,我建议去使用此解决方案,您可以避免嵌套布局。

我希望这个hepls!谢谢。

circle.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <size android:width="50dp"
        android:height="50dp"/>
    <stroke
        android:width="3dp"
        android:color="@color/black"/>
    <solid android:color="@color/black"/>
</shape>

在 ImageView 中 在

中添加
android:background="@drawable/circle"

谢谢大家的帮助。 此代码按我的意愿工作。 谢谢你!!