android 获取图片像素密度,android 获取屏幕的密度和像素 点
經(jīng)過(guò)測(cè)試發(fā)現(xiàn)屏幕的像素點(diǎn) 如果
density =1 那么 1dp = 1px
density =2 那么 1dp = 2px
density =3 那么 1dp = 3px
在字體設(shè)置的時(shí)候用dp比用px好,因?yàn)檫@樣可以防止在不同的分辨率上顯示的字體大小不同
textView_bacMsg = (TextView) findViewById(R.id.textView_bacMsg);
bacImg = (ImageView) findViewById(R.id.bacImg);
drawable = new MyProgressDrawable(this);
// 獲取屏幕密度(方法2)
DisplayMetrics dm = new DisplayMetrics();
dm = getResources().getDisplayMetrics();
float density? = dm.density;??????? // 屏幕密度(像素比例:0.75/1.0/1.5/2.0)
int densityDPI = dm.densityDpi;???? // 屏幕密度(每寸像素:120/160/240/320)
float xdpi = dm.xdpi;
float ydpi = dm.ydpi;
int screenWidth? = dm.widthPixels;????? // 屏幕寬(像素,如:480px)
int? screenHeight = dm.heightPixels;???? // 屏幕高(像素,如:800px)
RelativeLayout.LayoutParams? layoutParams =new? RelativeLayout.LayoutParams(-2, -2);
layoutParams.width = screenWidth-200;
layoutParams.height = screenWidth-200;
layoutParams.topMargin = (int) ((screenHeight - 240*density - ( screenWidth-200))/2);
layoutParams.leftMargin = (int) ((screenWidth- ( screenWidth-200))/2);
bacImg.setLayoutParams(layoutParams);
bacImg.setBackgroundDrawable(drawable);
drawable.start();
RelativeLayout.LayoutParams? layoutParams_text =(LayoutParams) textView_bacMsg.getLayoutParams();
layoutParams_text.topMargin =(int) ((screenHeight - 240*density - (layoutParams_text.height))/2);
Log.e("中間的字體寬度", layoutParams_text.width+"");
layoutParams_text.leftMargin = (int) ((screenWidth - (20*4*density))/2);
textView_bacMsg.setLayoutParams(layoutParams_text);
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的android 获取图片像素密度,android 获取屏幕的密度和像素 点的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: android扩散波动动画,使用WebG
- 下一篇: android span的用法,Andr