这篇文章主要介绍Android开发如何实现ImageView宽度顶边显示,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

在合浦等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站制作 网站设计制作按需定制网站,公司网站建设,企业网站建设,品牌网站设计,营销型网站建设,成都外贸网站建设公司,合浦网站建设费用合理。
具体如下:
ImageView 图片宽度顶边显示,高度保持比例
1、在布局中设置
主要是代码:
android:scaleType="fitXY" :填充宽度match_parentandroid:adjustViewBounds="true" :高度保持比例
2、代码实现
public class MImageView extends ImageView {
public MImageView(Context context) {
super(context);
}
public MImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Drawable drawable = getDrawable();
if (drawable != null) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) Math.ceil((float) width * (float) drawable.getIntrinsicHeight() / (float) drawable.getIntrinsicWidth());
setMeasuredDimension(width, height);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}以上是“Android开发如何实现ImageView宽度顶边显示”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!