【问题标题】:Image not fitting properly into Circular Image View图像不适合圆形图像视图
【发布时间】:2016-09-10 07:12:02
【问题描述】:

我有一个矩形图像,我想将其显示为圆形边框图像视图: 我做了一个这样的drawable:

<?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 但问题仍然存在。

请帮忙。

【问题讨论】:

  • 已经在这里回答了:stackoverflow.com/q/39423549/6816052
  • @NikunjParadva : 不能使用这个,因为我必须在项目的很多地方更改 ImageButton。
  • @Amit Upadhyay 而不是ImageButtonImageViewNikunj 说然后设置它。
  • @AmitUpadhyay 我认为圆形 Imagebutton 是不可能的,但使用 Imageview 我希望这个库对你有用

标签: android image bitmap imagebutton android-imagebutton


【解决方案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"/>

这肯定会帮助你!!!

【讨论】:

    【解决方案2】:

    使用此代码

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

    【讨论】:

    • 如问题中所述,我已经尝试了scaleType 的所有可能选项,但似乎没有任何帮助
    • 加载图片你用什么? android:src 还是 glide?​​span>
    猜你喜欢
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多