简体   繁体   English

xhdpi屏幕分辨率困难

[英]Difficulty in xhdpi screen resolution

eg:- Samsung Galaxy S III (1280 x 720) and Samsung Galaxy S 4 (1920 x 1080) uses resources from xhdpi. 例如:-Samsung Galaxy S III(1280 x 720)和Samsung Galaxy S 4(1920 x 1080)使用xhdpi中的资源。 I'm hvaing 3 icons in a row aligned left, centre and right with size of (256 x 256) but it gets overlapped on SIII and on s4 their is a wide gap between icons. 我连续3个图标在左,中和右对齐,大小为(256 x 256),但在SIII和s4上它们重叠了,它们在图标之间有很大的差距。

What should be the size of icon to fit it as 1/3 of screen's width or is there any workaround to do so? 图标的大小应为多少以适合屏幕宽度的1/3,还是有任何解决方法?

here is sample snapshot of layout after following mentioned solutions. 这是下面提到的解决方案后的布局示例快照。 http://postimg.org/image/97aabr2wd/ http://postimg.org/image/97aabr2wd/

its getting scaled properly but leaves space on top and bottom. 它的缩放比例适当,但在顶部和底部留有空间。 I want result similar to snapshot in this image http://postimg.org/image/r6ico4vil/ 我想要类似此图片中快照的结果http://postimg.org/image/r6ico4vil/

where 1, 2 and 3 should be of same height. 其中1、2和3的高度应相同。 Its just a space after 3 consecutive red, green and blue images. 在连续3个红色,绿色和蓝色图像之后,仅保留一个空格。 how to achieve this? 如何做到这一点? thanks in advance. 提前致谢。

The samsung Galaxy S4 is XXHDPI, and not XHDPI. 三星Galaxy S4是XXHDPI,而不是XHDPI。

Here is a way to check for the device density : 这是一种检查设备密度的方法:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int density = dm.densityDpi;
switch(density)
{
 case DisplayMetrics.DENSITY_LOW:
  Toast.makeText(context, "ldpi", Toast.LENGTH_SHORT).show();
  break;
 case DisplayMetrics.DENSITY_MEDIUM:
  Toast.makeText(context, "mdpi", Toast.LENGTH_SHORT).show();
  break;
 case DisplayMetrics.DENSITY_HIGH:
  Toast.makeText(context, "hdpi", Toast.LENGTH_SHORT).show();
  break;
 case DisplayMetrics.DENSITY_XHIGH:
  Toast.makeText(context, "xhdpi", Toast.LENGTH_SHORT).show();
  break;
 case DisplayMetrics.DENSITY_XXHIGH:
  Toast.makeText(context, "xxhdpi", Toast.LENGTH_SHORT).show();
  break;
}

I took if from this answer . 我从这个答案中得出结论

About having 3 images filling the whole screen width you can use a linear layout with layout weight. 关于使3张图像占据整个屏幕宽度,您可以使用具有布局权重的线性布局。

 <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="9" >

<ImageView
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="3" />

<ImageView
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="3" />

<ImageView
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="3" />
</LinearLayout>

In android- 在android-

px = dp * (dpi / 160) px = dp *(dpi / 160)

1.So in your first question 960dp x 720dp at 320dpi means 1920px x 1440px for xlarge screen in landscape mode using above formula. 1.因此在您的第一个问题中,使用上述公式,横向模式下的x大屏幕分辨率为960dp x 720dp(320dpi)意味着1920px x 1440px。

2.640dp x 480dp at 240dpi means 960px x 720px for large screen in landscape mode. 2.640dp x 480dp(240dpi)表示横向模式下大屏幕分辨率为960px x 720px。

enter link description here 在此处输入链接说明

You can't guaranty a 1/3 of the screen with just an image. 您不能仅凭图像保证屏幕的1/3。 even if two devices have the same dpi (or XHdpi) it doesn't mean they have the same size. 即使两个设备具有相同的dpi(或XHdpi),也不表示它们具有相同的尺寸。 The only way to do that is with code or in the layout xml. 唯一的方法是使用代码或在布局xml中。 Try use wights. 尝试使用紧身裤。

android:layout_width="0dp"
android:layout_weight="0.33"

with this code you guaranty that the view will be a 1/3 of the screen if width. 使用此代码,您可以确保视图宽度为屏幕的1/3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM