Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 像Google一样可选的圆形图像大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在用于个人资料照片的当前Google应用程序中创建可选择的圆形 ImageView?

这就是我所说的:

取消选择上面的图像,然后选择下面的图像.

我尝试复制配置文件图片1到1.

到目前为止我的工作:

loadedImage是显示的位图

@H_756_12@mImageView.setBACkground(createStateListDrawable()); mImageView.setImageBitmap(createRoundImage(loadedImagE));

使用的方法

private Bitmap createRoundImage(Bitmap loadedImagE) {
    Bitmap circleBitmap = Bitmap.createBitmap(loadedImage.getWidth(),loadedImage.getHeight(),Bitmap.Con@L_696_5@.ARGB_8888);

    BitmapShader shader = new BitmapShader(loadedImage,Shader.TileMode.CLAMP,Shader.TileMode.CLAMp);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    Canvas c = new Canvas(circleBitmap);
    c.drawCircle(loadedImage.getWidth() / 2,loadedImage.getHeight() / 2,loadedImage.getWidth() / 2,paint);

    return circleBitmap;
}

private StateListDrawable createStateListDrawable() {
    StateListDrawable stateListDrawable = new StateListDrawable();

    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShapE);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed },shapeDrawablE);
    stateListDrawable.addState(StateSet.WILD_CARD,shapeDrawablE);

    return stateListDrawable;
}

ImageView的大小是imageSizePx,图像的大小是imageSizePx – 3.因此,这意味着背景应该与图像重叠.哪个不起作用.

解决方法

非常简单的解决方案,感谢@CommonsWare的提示.

位图大小:imageSizePx – 3DP
ImageView的大小:imageSizePx

@H_756_12@mImageView.setBACkground(createStateListDrawable(imageSizePX)); mImageView.setImageBitmap(loadedImagE); private StateListDrawable createStateListDrawable(int sizE) { StateListDrawable stateListDrawable = new StateListDrawable(); OvalShape ovalShape = new OvalShape(); ovalShape.resize(size,sizE); ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShapE); shapeDrawable.getPaint().setColor(getresources().getColor(R.color@L_836_9@mecolor)); stateListDrawable.addState(new int[]{android.R.attr.state_presseD},shapeDrawablE); stateListDrawable.addState(new int[]{android.R.attr.state_focuseD},shapeDrawablE); stateListDrawable.addState(new int[]{},null); return stateListDrawable; }

大佬总结

以上是大佬教程为你收集整理的android – 像Google一样可选的圆形图像全部内容,希望文章能够帮你解决android – 像Google一样可选的圆形图像所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。