Android: Samsung S4 Screen size - android

I am trying to figure out the dimensions for the S4. What is the width and height. I want to create graphics and place them based on h and w. I read that the screen size ranges from 0-h and 0-w, but what are h and w?

S4 screen specs are 1080 x 1920, but you shouldn't use the actual screen size in pixels in your code.
Just use dp - which is a size which is independent in the screen density to design you Android app UI, this way, it will behave nicely for all screen sizes.
For more details see Supporting Multiple Screens Guidelines.

Here's some handy code if you need to find the size of various devices:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;
int screenHeight = size.y;

Related

Android DisplayMetrics display absolute size varies with orientation

Has anyone noticed this issue and resolved the way of getting the absolute display size consistently in both orientations?
Example, Nexus 5 (5.0.1):
Portrait: width = 1080 height = 1776
Landscape: width = 1794 height = 1080
I would have thought that the height in portrait would match the width in landscape. Initially suspected the status bar, but docs are clear. Anyway the status bar height in this example is 75px in either orientation and the diff in the example is 18px.
Code snippet for display width and height in pixels:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
String dimensions = String.format("width = %d height = %d", width, height);
Log.v(TAG, dimensions);
Assuming the display is FullHD acording to your logging there's something of 144px (48dp) height in portrait and 126px (42dp) width in landscape occupying the display (when scaling factor is 3 which is xxhdpi). I bet it's the navigation bar with Back, Home and Recent buttons. This is sufficient for choosing layouts.
EDIT:
If you need the full display size the following code is available from API 17:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else {
display.getSize(size); // correct for devices with hardware navigation buttons
}
EDIT2:
If you want to make sure you get correct result on API 14 through 16 consider following this answer along with its comments
https://stackoverflow.com/a/11004877/2444099 .
It's not the entire screen size, its the size of the UI that display metrics gives you. You have to factor in the amount of screen size taken up by the area taken up by the status bar (clock, battery level, signal strength bar) which will differ on orientation.

How to make layout for 8 inch tablet

Hello i am making an app in android which need to target 8 inch tablet. I can use weight sum to arrange my layout in proportion but in some layouts i have a button over imageview(in Relativelayout). Now when imageview expands the layout gets distorted. So please suggest me a way to target 8 inch tablet. Reading all other questions i could see sw-600dp but that is for 7 inch so what to do for 8 inch tablet. Moreover what is the resolution of 8 inch tablet.
Thanks. Plz help.
More over many of 8.0 inch tablets having the 1280 x 800 resolution. if you really want to know the exact resolution of your specific 8.0 inch tablet then simply you can get by using the following code
If you want the display dimensions in pixels you can use getSize:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
This method was introduced in Android API 13, so if you want to get display metrics for previous APIs use:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int wwidth = displaymetrics.widthPixels;
on Android you can specify smallest width on the resources. Examples:
layout-sw600dp/ < that's a 7" like the Nexus 7
layout-sw720dp/ < that's a 10" like the Nexus 10
so all you have to do is to find out what's the smallest width in DP for the 8 inches (probably something around 660dp) and create the resource folder for it.
Refer this link. Here they explained in detail regarding the screen support
http://developer.samsung.com/technical-doc/view.do;jsessionid=P0nhJ0Jh1VJhPQklhN1G1vJYrH5JWH2PYnv5RsP5pWfSxY86fgpb!361558248?v=T000000126
sw720dp will do it for you. Because 8 inch tablet lies in the bucket sw720.

android, get pixel size of screen?

I am making an app for a tablet which has a resolution of 1280 x 800, and I want custome graphics for it. But when i took a screenshot of the screen the resolution was 1024x600, why is this? What size background image would I make?!
As mentionned here : http://developer.android.com/reference/android/util/DisplayMetrics.html
if you want the pixel of your screen, you can write
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
and then, you can call :
int width = metrics.widthPixels;
int height = metrics.heightPixels;
in the simulator it is actually resized to fit your screen and takes in your screens resolutions nothing wrong with your code or images.
Screen shot dimension maynot be same as resolution.
you need to make graphics with 1280 x 800.
screen shot taken depend on theway how it is created,it doesnt have to be same resolution as display.

auto resizing textView with different density devices android

At the top of my app, I have a title which should be shown in the middle, and a button on the right. As the textViews length is behind my control, I sometimes have my title crossing the button due to long length of the content of it.
After following this, I somehow tend to solve the problem. My device was HTC desire. Unfortunately, if I check with Galaxy SIII, it doesn't do the trick.
I am wondering how I can manage this in terms of different devices with different densities.
My controls inside the relative layout
You can also check the device screen density by this--
WindowManager wm = (WindowManager) _context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
And can manage accordingly whats your apps needed..
just use weightsum in your xml and make width of all the views as fill parent ..... this makes auto resizing of your textview
you can maintain layouts according to their DPI`s
replicate the same XML data in XHDPI (As S3 falls in XHDPI) and test it similarly replicate the XML data in HDPI
but
keep in mind the following Thing Pixel Ratio of the layOut as
following
in LDPI its 1:0.75
in MDPI its 1:1
in HDPI its 1:1.5
in XHDPI its 1:2
Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
float density = dm.density;
int screenWidth = display.getWidth();
With this code above, you'll have your screen density as float.. So you can use it to calculate your textView's width like:
int newWidth = (int) (density * 100);
which 100 is here based size.
Or you can have a ratio according to your screenWdith.
int newWidth = screenWidth / 2;

Android WindowManager shows same screen size for different devices

I am debugging my application on 2 different Droid devices: Bionic and Droid3. When I use WindowManager to display device width & height, it shows 540x960 (portrait) and 960x540 (landscape) for both devices! How is that possible? The 2 devices are clearly of a different size. Here is the code:
Display display = getWindowManager().getDefaultDisplay();
final int width = display.getWidth();
final int height = display.getHeight();
Thanks,
Igor
I read that getWidth()/getHeight() is deprecated.
Try to use this:
Display display = getWindowManager().getDefaultDisplay();
Point displayDimensionInPixel = new Point();
display.getSize(displayDimensionInPixel);
I'm not shure right now because the Documentation isn't there anymore, but I think I can remember that getWidth()/getHeight() of Display dont return pixel dimensions.

Categories

Resources