Android开发如何动态设置控件等宽高
程序员文章站
2022-03-23 20:41:31
Android开发如何动态设置控件等宽高。
public static void setViewWidthByHeight(View view) {
final...
Android开发如何动态设置控件等宽高。
public static void setViewWidthByHeight(View view) { final View mv = view; final ViewTreeObserver vto = mv.getViewTreeObserver(); final ViewTreeObserver.OnPreDrawListener preDrawListener = new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { / int width = mv.getMeasuredWidth(); int height = mv.getMeasuredHeight(); android.view.ViewGroup.LayoutParams lp = mv.getLayoutParams(); lp.width = height; mv.setLayoutParams(lp); final ViewTreeObserver vto1 = mv.getViewTreeObserver(); vto1.removeOnPreDrawListener(this); return true; } }; vto.addOnPreDrawListener(preDrawListener); }
下一篇: WSH简介