Android的:如何在code使用DIP(密度独立像素)?密度、像素、独立、如何在

2023-09-06 07:39:25 作者:光一样的少年

我如何指定一个 INT 参数是浸?具体来说,怎么会写等价的:

 机器人:layout_width =50dip
机器人:layout_height =50dip
 

喜欢的东西...

 的LayoutParams PARAMS =新的LayoutParams(50,50)
 

解决方案 在android中怎么把checkbox设置成小的20dip 20dip大小的,但是设置成太20dip 20dip却只显示一半,

使用这里提到的公式http://developer.android.com/guide/practices/screens_support.html#screen-independence转换默认像素密度独立的像素。或检查该What是从Java code指定DIP尺寸正确的方法是什么?

How do I specify that an int parameter is in dip? Specifically, how would write the equivalent of:

android:layout_width="50dip" 
android:layout_height="50dip" 

Something like...:

LayoutParams params = new LayoutParams(50, 50)

解决方案

Use the formula mentioned here http://developer.android.com/guide/practices/screens_support.html#screen-independence for converting default pixel to density independent pixel. OR check this What is the correct way to specify dimensions in DIP from Java code ?