当前位置:网站首页>Glide set fillet image (support custom fillet position)
Glide set fillet image (support custom fillet position)
2022-04-23 01:30:00 【Jianren Yinkou】
There is a need to display data in recent projects , Fillet the leftmost picture in the parent control , At this point, the right angle of the displayed picture covers the fillet of the parent control , Therefore, it is necessary to fillet the picture before displaying .
On the Internet, most of them are realized through Transformation, stay transform Method , Then I found out Glide The built-in settings in the circular picture RoundedCorners class , Learn from this kind of information that can be provided officially TransformationUtils Tool class to implement , The specific implementation is as follows :
public class RoundRadiusTransform extends BitmapTransformation {
// The full path of the actual class is used here
private static final String ID = "com.xxx.xxx.xxxx.xxx.RoundRadiusTransform";
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
private final int roundingRadius;
private boolean isLeftTop, isRightTop, isLeftBottom, isRightBottom;
private static RoundRadiusTransform mInstance;
public RoundRadiusTransform(int roundingRadius) {
this.roundingRadius = roundingRadius;
}
/**
* The part where the fillet needs to be set
*
* @param leftTop top left corner
* @param rightTop Upper right corner
* @param leftBottom The lower left corner
* @param rightBottom The lower right corner
*/
public void setNeedCorner(boolean leftTop, boolean rightTop, boolean leftBottom, boolean rightBottom) {
isLeftTop = leftTop;
isRightTop = rightTop;
isLeftBottom = leftBottom;
isRightBottom = rightBottom;
}
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
return TransformationUtils.roundedCorners(pool, toTransform,
isLeftTop ? roundingRadius : 0,
isRightTop ? roundingRadius : 0,
isRightBottom ? roundingRadius : 0,
isLeftBottom ? roundingRadius : 0);
}
public static RoundRadiusTransform getDefault() {
if (mInstance == null) {
synchronized (RoundRadiusTransform.class) {
if (mInstance == null) {
mInstance = new RoundRadiusTransform(ScreenUtils.dp2px(MainApplication.getInstance(), 6));
mInstance.setNeedCorner(true, false, true, false);
}
}
}
return mInstance;
}
@Override
public boolean equals(Object o) {
if (o instanceof RoundRadiusTransform) {
RoundRadiusTransform other = (RoundRadiusTransform) o;
return roundingRadius == other.roundingRadius;
}
return false;
}
@Override
public int hashCode() {
return Util.hashCode(ID.hashCode(), Util.hashCode(roundingRadius));
}
@Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update(ID_BYTES);
byte[] radiusData = ByteBuffer.allocate(4).putInt(roundingRadius).array();
messageDigest.update(radiusData);
}
}
The default setting in the above example is left 6dp The display style of the right angle of the fillet . If you read it RoundedCorners Source code , You will find that there are great similarities , It's just transform Method returns differently .
So sometimes there's no need to reinvent the wheel , Some wheel parts are in tools provided by third parties , All we need is to take some time to understand the group and spell it out .
版权声明
本文为[Jianren Yinkou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220942099367.html
边栏推荐
- 天梯赛L2-6 树的遍历
- Learning of gin framework -- golang
- Is 2022 software testing easy to learn? How long will it take? (learning roadmap attached)
- 10月24号是什么?中国的高级程序员为什么没有五六十岁的,而国外人、、、,玉念聿辉带你过1024程序员节日
- Software maintenance exercises
- 12 years of testing predecessors give you some suggestions for learning software testing
- iTextSharp 基础结构
- Innovative practice of short video content understanding and generation technology in meituan
- Itextsharp infrastructure
- (product resources) mingdeyang ad8488 module high performance digital X-ray FMC interface 128 analog channel high-speed ADC chip
猜你喜欢
Small example of gin - get request 1-handle handles get requests
无关联进程间通信 —— 命名管道的创建和使用
京东一面:子线程如何获取父线程 ThreadLocal 的值?我蒙了。。。
Counting garlic guest: the solution of the equation
Oracle database query lock table SQL script and delete lock information script (necessary for database development ETL and DBA)
200. Number of islands
C language guessing game and trickery game
Android本地数据库基础操作|多线程操作数据库|数据库的增删改查|批量插入数据库|线程池基础使用|玉念聿辉
Function encapsulation such as addition, deletion, modification and query of linked list (summary)
Is it difficult for girls to learn software testing?
随机推荐
直播软件|IPTV直播软件|电视直播|TVPlayer-IPTV-EasyPlayer|友窝直播|超级直播软件定制开发
Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
gin -get请求的小示例1-Handle处理GET请求
VRF in Mina
找数字(DFS)
Gbase 8s存儲結構簡介及空間管理
Prince saves Princess (DFS)
Rotation slice
清研环境深交所上市:年营收1.8亿 市值41亿
Gbase 8s group by function introduction
Qingyan environment and Shenzhen Stock Exchange listing: annual revenue of 180 million and market value of 4.1 billion
Gbase 8s 并发控制之封锁粒度
DFS奇偶性剪枝
Soatest preliminary understanding
Itextsharp displays Chinese fonts
iTextSharp 显示中文字体
Find number (DFS)
JD side: comment un thread enfant obtient - il la valeur de threadlocal du thread parent? Je suis couvert...
Gbase 8t index
What is the legal basis and procedure for Tami dog sharing | state owned equity transfer?