Android常见尺寸的获取

代码:

                //获取控件尺寸(控件尺寸只有在事件里面可以获取到)
                TextView mTV = (TextView) findViewById(R.id.iv_view);
                int width = mTV.getWidth();
                int height = mTV.getHeight();

                //获取图片尺寸
                Drawable drawable = ContextCompat.getDrawable(this, R.drawable.about_logo);
                int width2 = drawable.getIntrinsicWidth();
                int height2 = drawable.getIntrinsicHeight();

                //获取屏幕尺寸
                DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);
                int width3 = dm.widthPixels;
                int height3 = dm.heightPixels;

结果:

PS:单位都是像素
Android常见尺寸的获取_第1张图片

你可能感兴趣的:(尺寸,图片尺寸,屏幕尺寸,控件尺寸)