天天看點

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常見尺寸的擷取

繼續閱讀