SmartImageView
2016-01-21 22:30
274 查看
==
==
public class SmartImageView extends ImageView { public SmartImageView(Context context) { super(context); } public SmartImageView(Context context, AttributeSet attrs) { super(context, attrs); } public SmartImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { try { Drawable drawable = getDrawable(); if (drawable == null) { setMeasuredDimension(0, 0); } else { float imageRatio = (float)drawable.getIntrinsicWidth() / drawable.getIntrinsicHeight(); float viewRatio = (float)MeasureSpec.getSize(widthMeasureSpec) / MeasureSpec.getSize(heightMeasureSpec); // Image is wider than the display (ratio) if (imageRatio >= viewRatio) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = (int) (width / imageRatio); setMeasuredDimension(width, height); } // Image is taller than the display (ratio) else { int height = MeasureSpec.getSize(heightMeasureSpec); int width = (int)(height * imageRatio); setMeasuredDimension(width, height); } } } catch (Exception e) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } }
==
相关文章推荐
- Add a Syscall
- select/poll/epoll on serial port
- Android Studio导入项目非常慢的解决办法
- JavaScript之函数和this
- 排序—基数排序(js实现)
- 并查集+欧拉回路
- Generate Ubuntu Install Media On Mac
- 遥望布达拉——DAY14 左贡-邦达
- Cordys BOP租户使用中常见疑问——租户对接口进行授权
- 动态规划-三角形
- C语言结构体
- Tomcat设置IP,实现局域网内机器访问
- 【转】细说new与malloc的10点区别
- Bare Medal on BCM2835 and BCM2836
- 第十篇 javascript基础语法
- java简单数据类型
- leetcode--Unique Paths && Unique Paths ii
- centos下的lnmp环境搭建
- UVA 1608 Non-boring sequences (递归分治)
- CS1.6 for win7 win10