【问题标题】:Image corners are not getting rounded while using Universal image loader使用通用图像加载器时图像角没有变圆
【发布时间】:2016-10-11 01:12:07
【问题描述】:

我在使用通用图像加载器加载图像时遇到了奇怪的问题。 我想显示所有角为圆角的图像,但输出图像未按要求显示。

下面是我在适配器项 xml 中的代码 -

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/container_rl"
    android:background="@color/transparent_color"
    android:layout_height="300dp">

<ImageView
    android:id="@+id/object_iv"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"

    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<View
    android:background="@drawable/rounded_corner_bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

 <TextView
    android:id="@+id/name_tv"
    android:layout_centerInParent="true"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginLeft="@dimen/space_20"
    android:layout_marginRight="@dimen/space_20"
    android:text="@string/app_name"
    android:textColor="@color/white"
    android:textSize="@dimen/size_18"/>
</RelativeLayout>

这是适配器中的代码 -

ImageLoaderUniversal.ImageLoadWithRoundedCorners(mContext,ImageURI, mFeedIV);

最后是加载图片的代码 -

  public static void ImageLoadWithRoundedCorners(Context mContext,final String URl, final ImageView imageView){
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.mipmap.ic_default_media)
            .showImageForEmptyUri(R.mipmap.ic_default_media)
            .showImageOnFail(R.mipmap.ic_default_media)
            .cacheOnDisk(true)
            .displayer(new RoundedBitmapDisplayer(25))
            .build();

    ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(mContext).defaultDisplayImageOptions(
            options).memoryCache(new WeakMemoryCache());
    ImageLoaderConfiguration config = builder.build();
    imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited()) {
        imageLoader.init(config.createDefault(mContext));
    }
    imageLoader.displayImage(URl, imageView, options);
}

在此处添加有关使用上述代码如何显示图像的屏幕截图。

请提供您对我的问题的解决方案。

TIA

【问题讨论】:

    标签: android image universal-image-loader android-bitmap


    【解决方案1】:

    试试这个

    options = new DisplayImageOptions.Builder()
        .displayer(new RoundedBitmapDisplayer(50))
        .showStubImage(R.drawable.ic_app)
        .showImageForEmptyUri(R.drawable.camera)
        .showImageOnFail(R.drawable.ic_error)
        .cacheOnDisc()
        .build();
    

    【讨论】:

    • 尝试了同样的结果
    【解决方案2】:

    请在您的依赖项中编译它并使用下面给出的 xml 代码代替 imageview。

    编译'de.hdodenhof:circleimageview:2.0.0'

     <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/ivUserImage_nfp"
                            android:layout_width="60dp"
                            android:layout_height="60dp"
                            android:src="@drawable/profile_img"
                            app:civ_border_color="@color/textcolor"
                            app:civ_border_width="1dp" />
    

    您可以根据需要设置边框颜色和宽度。仅使用通用图像加载器来加载图像。

    【讨论】:

    • 我不想显示完整的圆形图像,我只需要圆角
    猜你喜欢
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    相关资源
    最近更新 更多