图像不适合圆形图像视图
Image not fitting properly into Circular Image View
我有一个矩形图像,我想将其显示到圆形边框图像视图中:
我制作了一个这样的可绘制对象:
<?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"/>
看起来像这样:
但是当我将图像加载到其中时,它看起来像这样:
它没有完全覆盖 ImageButton。我希望加载的图片以循环方式覆盖ImageButton。
我已经尝试更改 android:scaleType
的所有可能选项,但没有一个符合要求,我什至尝试将 ImageButton 更改为 ImageView,但问题仍然存在。
请帮忙。
使用此代码
<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="fitCenter"
android:layout_marginBottom="20dp"/>
在此之后,如果您遇到同样的问题,请将 scaleType 更改为另一个。
嘿@Amit Upadhyay 你应该试试这个很棒的库来获得一个完美的个人资料的快速循环 ImageView images.This 基于 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"/>
一定能帮到你!!!
我有一个矩形图像,我想将其显示到圆形边框图像视图中: 我制作了一个这样的可绘制对象:
<?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"/>
看起来像这样:
但是当我将图像加载到其中时,它看起来像这样:
它没有完全覆盖 ImageButton。我希望加载的图片以循环方式覆盖ImageButton。
我已经尝试更改 android:scaleType
的所有可能选项,但没有一个符合要求,我什至尝试将 ImageButton 更改为 ImageView,但问题仍然存在。
请帮忙。
使用此代码
<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="fitCenter"
android:layout_marginBottom="20dp"/>
在此之后,如果您遇到同样的问题,请将 scaleType 更改为另一个。
嘿@Amit Upadhyay 你应该试试这个很棒的库来获得一个完美的个人资料的快速循环 ImageView images.This 基于 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"/>
一定能帮到你!!!