简单实现ImageView宽度填满屏幕,高度自适应的两种方式
来源:互联网 发布:2017山东网络歌手大赛 编辑:程序博客网 时间:2024/06/05 07:53
两种方式
1.重写View的onMeasure方法参考这里easion_zms的专栏
核心代码
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ Drawable d = getDrawable(); if(d!=null){ // ceil not round - avoid thin vertical gaps along the left/right edges int width = MeasureSpec.getSize(widthMeasureSpec); //高度根据使得图片的宽度充满屏幕计算而得 int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth()); setMeasuredDimension(width, height); }else{ super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
2.设置ImageView的属性:
//宽度填满屏幕
android:layout_width=”match_parent”
android:scaleType=”fitXY”
android:layout_height=”wrap_content”
//保持比例,一定要设置
android:adjustViewBounds=”true”
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitXY" />
0 0
- 简单实现ImageView宽度填满屏幕,高度自适应的两种方式
- ImageView宽度填满屏幕,高度自适应
- ImageView宽度填满屏幕,高度自适应
- ImageView宽度填满屏幕,高度自适应
- [CAQ4]ImageView宽度固定,高度自适应的实现方式
- ImageView宽度填充屏幕,高度自适应
- 宽度固定,高度自适应的imageview
- 实现UILabel自适应高度的两种方式
- Android获得屏幕高度和宽度的两种方法
- 简单的iframe自适应高度和宽度
- 使用Java的Swing组件获取屏幕的高度和宽度(两种方式:包含任务栏高度和不包含任务栏高度)
- android ImageView 宽度设定,高度自适应
- android ImageView 宽度设定,高度自适应
- android ImageView 宽度设定,高度自适应
- android ImageView 宽度设定,高度自适应
- Android ImageView设置宽度,高度自适应
- android 图片宽度填满屏幕宽度,图片高度根据图片的比例自动匹配,这样就不会拉伸图片
- cell高度自适应实现的最简单方式
- Android 视频文件加密
- POJ 1050 To the Max
- 快速排序代码
- Exception in thread "http-8080-3" java.lang.OutOfMemoryError: PermGen space
- 初识《MVC》
- 简单实现ImageView宽度填满屏幕,高度自适应的两种方式
- js实现fieldset折叠
- Unity融合iOS所遇到的一些奇怪问题
- 给我一个寒假,我就能撬动未来!
- 简单的使用WKWebView
- Android 程序打包及签名
- android studio 调试----------Watting for processing
- JQuery经典例子:可拉伸菜单
- FFmpeg 2.8.4 移植到android平台(一)