需求:
要求移动端图片宽高1:1显示.并且图片宽度要充满手机屏幕的宽度. 怎么办?
方法1: onMeasure()方法:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if(mScale != -1){
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((int) (MeasureSpec.getSize(widthMeasureSpec) * mScale), MeasureSpec.getMode(widthMeasureSpec)));
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
其中mScale 代表 height/width的值.sample
<com.mingle.widget.ScaleLayout
android:layout_width="fill_parent"
app:scale="0.75"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:src="@mipmap/bg"
android:scaleType="fitXY"
android:layout_height="fill_parent" />
</com.mingle.widget.ScaleLayout>
用ScaleLayout 包裹ImageView,用 app:scale 设置宽高比: |

免费ecshop仿小米商城模板
人气:17098
ecshop大气综合保健用品商
人气:723
zencart手机数码模板
人气:2065
仿1元云购精品程序源码
人气:9557
YourStore外贸英文时尚服饰
人气:261
ecshop仿QQ商城综合模板
人气:1109