gpt4 book ai didi

android - 图像不适合圆形 ImageView

转载 作者:行者123 更新时间:2023-11-29 19:34:25 24 4
gpt4 key购买 nike

我有一个矩形图像,我想将它显示到一个圆形边框 ImageView 中:我做了一个这样的可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="100dp" />
<solid android:color="#41ba7a" />
<stroke
android:width="3dip"
android:color="#f9f9f9" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>

我在 ImageButton 中使用它:

<ImageButton
android:id="@+id/service_image_on_orderpage"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="@drawable/profile_circular_border_imageview"
android:elevation="5dp"
android:padding="20dp"
android:scaleType="centerCrop"
android:layout_marginBottom="20dp"/>

这看起来像这样:

enter image description here

但是当我将图像加载到其中时,它看起来像这样:

enter image description here

它没有完全覆盖 ImageButton。我希望加载的图片以循环方式覆盖 ImageButton。

我已经尝试更改 android:scaleType 的所有可能选项,但没有一个符合要求,我什至尝试将 ImageButton 更改为 ImageView,但问题仍然存在。

请帮忙。

最佳答案

嘿@Amit Upadhyay,你应该试试这个很棒的库,以获得一个非常适合个人资料图像的快速圆形 ImageView。这是基于 Vince Mi 的 RoundedImageView,它本身是基于 Romain Guy 推荐的技术

要使用这个库,您需要像下面这样在您的 gradle 中添加依赖项:

dependencies {
...
compile 'de.hdodenhof:circleimageview:2.1.0'
}

为了使用它,将小部件添加到您的布局 xml 文件中,如下所示:

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>

这肯定对您有帮助!!!

关于android - 图像不适合圆形 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39423573/

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