![](/img/trans.png)
[英]How should i know the phone that has the specified arguments is the hdpi or ldpi
[英]How to know if I should use ldpi in a layout
大家好,我正在努力实现多屏支持。 是否有类似的情况?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contatti);
//if (device in use , use ldpi ) { do something
else{
Button btnNavigator = (Button) findViewById(R.id.btnNavigator);
GoogleMap map=((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.moveCamera(CameraUpdateFactory.newLatLngZoom(STARTING_POINT, 5));
非常感谢。 你能给我举个例子吗?
试试这个代码:
private final boolean isLdpi()
{
final DisplayMetrics metrics =
Resources.getSystem().getDisplayMetrics();
final float scale = metrics.density;
return (scale == 0.75); // ldpi = 0.75, mdpi = 1.0, hdpi = 1.5, xhdpi = 2.0, xxhdpi = 3.0, ...
}
用法:
if (isLdpi)
{
// It's ldpi: do something
}
根据谷歌
小屏幕的尺寸至少为426dp x 320dp。
因此,找出设备的宽度,然后进行比较。
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
//this gives you the pixels and no the dp
metrics.heightPixels;
metrics.widthPixels;
//convert to dp
public static float convertDpToPixel(float dp, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return px;
}
请在此处查看更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.