2023年7月15日发(作者:)
简单实现ImageView宽度填满屏幕,⾼度⾃适应的两种⽅式⽅法⼀:
//乘以2是因为左右两侧的宽度//bobaoArcWidth bobaoArcHeight 原始图⽚宽⾼int height = (int) (width / (loat(bobaoArcWidth)) * (loat(bobaoArcHeight)));//设置图⽚参数Params layoutParams = outParams();// = _PARENT; = width; = height;outParams(layoutParams); ragment(mContext, bobaoArcPic, istItemIamge);⽅发⼆public class ResizableImageView extends ImageView {public ResizableImageView(Context context) {
super(context);
}
public ResizableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
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 = e(widthMeasureSpec);
//⾼度根据使得图⽚的宽度充满屏幕计算⽽得
int height = (int) ((float) width * (float) rinsicHeight() / (float) rinsicWidth());
setMeasuredDimension(width, height);
}else{
ure(widthMeasureSpec, heightMeasureSpec);
}
}
} android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/test" android:background="#FF0"/> Three根据图⽚的宽度,⾼度,来按⽐例显⽰final String app_arc_pic = (position).ad_pic;String adPicHeight = (position).ad_pic_height;String adPicWidth = (position).ad_pic_width;int adPicH = nt(adPicHeight);int adPicW = nt(adPicWidth);int width = dowManager().getDefaultDisplay().getWidth(); int height = width * adPicH / adPicW; Params para = outParams(); = height; outParams(para); LogUtils.e(TAG , "============拿到的app_arc_pic==========" +app_arc_pic); iThread(new Runnable() { @Override public void run() { (activity) .load(app_arc_pic) .placeholder(_message_tozhi_new) .error(_message_tozhi_new) .into(imageView); } });
发布者:admin,转转请注明出处:http://www.yc00.com/web/1689430656a247045.html
评论列表(0条)