==

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);
}
}
}

==

最新文章

  1. 关于git的简单实用命令
  2. sqlalchemy
  3. C# 调用Adodb对Access数据库执行批量插入
  4. PAT 1002. 写出这个数 (20)
  5. BestCoder8 1001.Summary(hdu 4989) 解题报告
  6. MYSQL INSERT INTO SELECT 不插入重复数据
  7. __block存储类型
  8. 初来乍到--------smarty
  9. win10十周年更新后cent os 虚拟机无法连接到xshell
  10. android中的 Toast 和 AlertDialog
  11. 【MYSQL】解决Mysql直接登录问题(删除匿名用户)(转)
  12. CVE-2016-10190 FFmpeg Http协议 heap buffer overflow漏洞分析及利用
  13. String 经常用法最优算法实现总结 (二)
  14. java中解决小数精度问题
  15. SCSS 使用@each 方法循环遍历数组颜色并给li赋值
  16. .net core 使用NPOI填充Word模板导出Word
  17. CGI-- FASTCGI
  18. c++ primer读书笔记之c++11(三)
  19. (转)Terraform,自动化配置与编排必备利器
  20. java代码块执行顺序

热门文章

  1. 今天工作中遇到的问题!echart.js
  2. mvc+mysql+EF
  3. PhpStorm破解教程
  4. js获取div相对屏幕的坐标位置
  5. c#闭包(转)
  6. 【线段树】bzoj1756 Vijos1083 小白逛公园
  7. eclipse 配色方案
  8. MIPS ABI n32意味着什么?
  9. requirejs+angularjs搭建SPA页面应用
  10. [c语言]字符数组、字符串定义