图像无法正确适合圆形图像视图

时间:2016-09-10 07:12:02

标签: android image bitmap imagebutton android-imagebutton

我是一个矩形图像,我希望将其显示为圆形边框图像视图: 我做了这样的抽奖:

<name>.github.io

我在ImageButton中使用它:

<?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>

这看起来像这样:

enter image description here

但是当我将图像加载到其中时,它会显示如下:

enter image description here

它没有完全覆盖ImageButton。我希望加载的图片应该以循环方式覆盖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更改为ImageView,但问题仍然存在。

请帮忙。

2 个答案:

答案 0 :(得分:1)

嘿@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"/>

这对您有帮助!!!

答案 1 :(得分:0)

使用此代码

  <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更改为另一个。