[英]rounded corner imageview programmatically
I want to set a rounded corner on my ImageView and here is code:我想在我的 ImageView 上设置一个圆角,代码如下:
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setLayoutParams(up);
layout.addView(frameLayout);
CardView cardView = new CardView(this);
cardView.setCardElevation(0);
cardView.setRadius(20);
cardView.setMaxCardElevation(0);
cardView.setLayoutParams(upz);
frameLayout.addView(cardView);
ImageView imageView = new ImageView(this);
String imageuri = listgambarpromo.get(i);
if (!this.isFinishing()) {
Glide.with(getBaseContext())
.load(imageuri)
.error(R.drawable.promoe)
.placeholder(R.drawable.promoe)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.fitCenter()
.into(imageView);
}
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(upz1);
cardView.addView(imageView);
I've set the ImageView inside the CardView, but it doesn't work and shown square on the corners我在 CardView 中设置了 ImageView,但它不起作用并且在角落显示为正方形
What should I do with my codes?我应该如何处理我的代码?
you already use Glide library for image.您已经将 Glide 库用于图像。 So there is make round option
所以有 make round 选项
Glide.with(context)
.load(url)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(20)))
.into(imageView);
like this.像这样。
if you want to make circle,如果你想画圈,
RequestOptions options = new RequestOptions()
.circleCrop()
.placeholder(R.drawable.img_nonemymenu)
.error(R.drawable.img_nonemymenu);
Glide.with(mContext).setDefaultRequestOptions(options)
.load(url)
.circleCrop()
.into(imageView);
like this.像这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.