FrameLayout中的Imageview是拉伸scaletype是centercrop [英] Imageview inside FrameLayout is stretching scaletype is centercrop

查看:640
本文介绍了FrameLayout中的Imageview是拉伸scaletype是centercrop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要带有圆角的 ImageView ,所以我在 ImageView > framelayout ,当我设置 scaleType centerCrop 时,图片集在 ImageView 在第一次加载时伸展,再次刷新页面图像没有拉伸并设置圆角。我怎么能避免第一次拉伸。谢谢提前

这是XML代码

In my application I need ImageView with rounded corners, So I have set ImageView inside framelayout, When I set the scaleType centerCrop, the image set inside the ImageView is stretching in first loading and, again refreshing the page the image is not stretching and set with round corners.How can I avoid the first stretching.Thanks in advance
Here is the XML code

<FrameLayout
    android:id="@+id/imageframe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/dp_80"
        android:layout_height="@dimen/dp_80"
        android:background="@drawable/image_rounded"
        android:src="@drawable/dummypost1"
        android:scaleType="centerCrop"/>

    <ImageView
        android:src="@drawable/image_rounded"
        android:layout_width="@dimen/dp_80"
        android:layout_height="@dimen/dp_80"
        android:scaleType="centerCrop"/>

</FrameLayout>


推荐答案

如果你想要 ImageView带圆角的,不需要像这样包装。

If you want an ImageView with rounded corners, there is no need for wrapping like this.

你只能使用 ImageView 在您的布局中并使用 glide ,您可以使用此方法应用圆角。

you can use only ImageView in your layout and using glide, you can apply round corners using this method.

首先在您的布局中gradle write,

first in your gradle write,


compile'c​​om.github.bumptech.glide:glide:3.7.0'

compile 'com.github.bumptech.glide:glide:3.7.0'

带圆角的图像,

public void loadImageWithCorners(String url, ImageView view) {
    Glide.with(context)
            .load(url)
            .asBitmap()
            .centerCrop()
            .placeholder(R.color.gray)
            .error(R.color.gray)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(new BitmapImageViewTarget(view) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCornerRadius(32.0f); // radius for corners
                    view.setImageDrawable(circularBitmapDrawable);
                }
            });
}

通话方式:

loadImageWithCorners("your url","your imageview");

这篇关于FrameLayout中的Imageview是拉伸scaletype是centercrop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆