简体   繁体   中英

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. 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.

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?

here is sample snapshot of layout after following mentioned solutions. 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/

where 1, 2 and 3 should be of same height. Its just a space after 3 consecutive red, green and blue images. how to achieve this? thanks in advance.

The samsung Galaxy S4 is XXHDPI, and not 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.

 <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-

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.

2.640dp x 480dp at 240dpi means 960px x 720px for large screen in landscape mode.

enter link description here

You can't guaranty a 1/3 of the screen with just an image. even if two devices have the same dpi (or XHdpi) it doesn't mean they have the same size. The only way to do that is with code or in the layout 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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