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.
Related
I would like to use screen width/height as a basis to handle "size" issues in different devices.
I tried the following code, however, it can only get the "resolution" but not "screen size".
DisplayMetrics displayMetrics= getResources().getDisplayMetrics();
width = displayMetrics.widthPixels;
height = displayMetrics.heightPixels;
For example, my 7" tablet returns 600 width and my 4.3" phone returns 540 width.
It's unreasonable since tablet's size is almost a double of phone.
How can I get the real size under human vision or I should go for other approach to handle size issue?
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;
Is there a way to make Android believe the current device has a certain screen size (pixels, not density) which is smaller than the actual display size (again pixels, not density)?
I need the following: On a device (not emulator) with a 1280x720 pixel (for example) display I want to use only 800x480 pixels - resulting in a homescreen attached to one of the corners and the rest of the display left black (or whatever color).
This has nothing to do with screen resolution since changing the resolution would fill the complete screen - which is what I don't want (see above).
Similar questions on SO have not been answered with any help.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.heightPixels;
metrics.widthPixels;
You can fix height and width of your main layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="800px"
android:layout_width="480px">
...
...
</RelativeLayout>
Is there an API in Android that returns the full screen height of the device? I'm interested in the full height as specified in the device spec, not the height of the viewable screen as returned by
android.view.Display.getHeight();
I spent some time looking for this and didn't find anything like what you're asking for. Part of the problem is that the bar that takes up the pixels they're not including can potentially be of different sizes.
What I ended up doing is measuring the width of the device (which is the full width) and the not-quite-full-height to match against the standard resolutions with an approximate. It's not great. If you really need it exact, you can force an orientation change to match both dimensions exactly. That's pretty gross, though.
The real answer is that you're not supposed to care about the exact dimensions of the hardware and design using the OS-provided size buckets.
Does this not work for you?
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
displayHeight = dm.heightPixels;
For me, displayHeight returns 960 pixels on my HTC Sensation
Try heightPixels on a DisplayMetrics object.
There are some screen resolutions already defined in Android.
They are:
QVGA (240×320, low density, small screen)
WQVGA (240×400, low density, normal screen)
FWQVGA (240×432, low density, normal screen)
HVGA (320×480, medium density, normal screen)
WVGA800 (480×800, high density, normal screen)
WVGA854 (480×854 high density, normal screen)
How do I know which type my device screen resolution is?
Use DisplayMetrics to get screen info from your device.
Sample code:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
final int height = dm.heightPixels;
final int width = dm.widthPixels;
Have you tried to search the specifications of your device? i.e. from Wikipedia's Nexus One article, you can find Nexus one screen resolution:
Display 480 x 800 px (PenTile RGBG), 3.7 in (94 mm), 254 ppi, 3:5 aspect ratio, WVGA, 24-bit color AMOLED with 100,000:1 contrast ratio and 1 ms response rate
That's a starting point...