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.
Related
I have three layouts :
/layout/layout.xml
/layout-xhdpi/layout.xml
/layout-xxhdpi/layout.xml
And i have two emulators :
Nexus 5x with Api level 28 screen size 1080x1920 420dpi
Pixel 3xl with Api 28 screen size 1440x2960 560dpi
What do I expect?
Nexux 5x should select the layout in /layout-xhdpi/layout.xml
Pixel 3xl should select layout in /layout-xxhdpi/layout.xml
What happens instead?
Both devices select layout in layout-xxhdpi.
I have also tried to replace by folder such as layout-sw420dp and layout-sw560dp one or both emulator select another layout.
Why does this happen, is there something?
Considering you are running one project on two devices you must go as per following approch:
set the setContentView(R.layout-xhdpi.layout.xml); in java
then tun the project on Nexux 5x
now set the setContentView(R.layout-xxhdpi.layout.xml); in java
then run the project on Pixel 3xl
If anything concerns you please leave a comment
First get the screen size of device by using:
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
After this you can use if else statement like
if(height==first phone display height)
{set the setContentView(R.layout-xhdpi.layout.xml);}
Else{setContentView(R.layout-xxhdpi.layout.xml);
}
Remember you need to pass exect screen size at place of first phone screen height
I am new to android studio; so please excuse if the query is trivial. My problem is with understanding the layouts.
My layout and the corresponding values folder is as shown below. My problem is that a correct layout is not being picked up. For example, for Nexus 4 (4.7inch, 768x1280, xhdpi), in the landscape mode, the layout is being picked up from the 'layout' folder. As per my understanding (which might be totally wrong :) ) it should have been picked from layout-sw720dp-xhdpi. Any suggestions please?
layout-problem
sw stands for smallest width. So if the a device has a width of 320dp in portrait mode and 720dp in landscape mode then you end the device's smallest width is 320dp.
Try use layout-w720dp-xhdpi instead of layout-sw720dp-xhdpi and see if it works.
How to calculate device dimensions in dp
Calculate the PPI (Pixel per inch) of the device.
Calculate the dimensions of the device using dp
Where:
= Screen width in pixels
= Screen height in pixels
= Screen diagonal in pixels
= Pixels per inch
= Screen diagonal in inches
Edit: According to Wikipedia "The Nexus 7 (2013) screen now has a 1920×1200 pixel resolution (960dp × 600dp)". So its smallest width is 600dp which is why your layout isn't being used.
Proof
PPI = (√(19202 + 12002))/7.02 = 322.53
Width in dp = (1920*160)/322.53 = 952.47 = Roughly 960dp
Height in dp = (1920*160)/322.53 = 595.29 = Roughly 600dp
I have a 1st Generation Nexus 7 that I am testing with. The app I'm working on only supports portrait. I'm trying to use the h1024dp numeric selector on the drawable directory to use specific images for devices like the Nexus 7. My directory is named:
drawable-h1024dp-hpdi
It is my understanding that any hpdi device that has a height of 1024 or more would use the drawable in the directory above.
I'm using hpdi as the second selector on that directory because my Nexus 7 is pulling its other drawables from the drawable-hdpi directory.
The screen size of my Nexus 7 is 1205 x 800 as detected by this code:
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point screenSize = new Point();
display.getSize(screenSize);
screenHeight = screenSize.y;
screenWidth = screenSize.x;
My app is NOT using the drawables in the drawable-h1024dp-hpdi directory as I expected it would.
What am I missing?
What am I missing?
1024dp would be a height of 1024 density-independent pixels. One density-independent pixel is 1/160th of an inch, so 1024 of them are 6.4 inches. Your Nexus 7 does not have a screen size that is 6.4 inches high -- it is about 5.9 inches. Hence, that resource set does not qualify.
Or, to look at it another way, the screen height is 1280px at ~213 dots per inch (-tvdpi), which works out to around 960dp.
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;
I have two tablet devices:
1) Asus Memo Pad 172V tablet
Specs given online as: 600 * 1024 pixels, 7.0 inches (~170 ppi pixel density) LINK
Specs through code: 1024 * 552 pixels, 7.0 inches (160 ppi pixel density)
2) MID 7510 tablet
Specs given online as: 800 * 480 pixels, 7.0 inches (no density mentioned anywhere) LINK
Specs through code: 1024 * 552 pixels, 7.0 inches (160 ppi pixel density)
My problem is:
- Both the tablets have the same density and resolutions (by code), so how can I distinguish between them in order to set the bitmap height (width is coming correct for both) as in case of MID7510, the bitmap height is extended slight down.
- Is there any other factors that are responsible for causing different bitmap sizes for both
tablets ?
- Why are specs coming different by code and are given different online ?
Code to get density and resolution:
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
// Display device dpi (density) value in pixels
int screenDPIy = (int)dm.ydpi;
I'll try to answer to each question but I'll start by the more important one:
- Why are specs coming different by code and are given different online?
Because you find online what material is used for the device, its usually the correct values. You find by code specifications that are set up by the constructor when they are building their android version for their devices. Meaning : it can be false! especially for devices from unknown constructor or Chinese low cost such as 'weisung'.
Given that, answers for the other questions:
- Is there any other factors that are responsible for causing different bitmap sizes for both
tablets?
I dont think so, they have got different screen size and density but system think they are the same... it explain the difference on the final bitmap size.
- How can I distinguish between them?
Definitively not from the screen specifications. If you really need to manage 'weisung' devices you can always check for manufacturer in the device configuration by code. (Assuming they have correctly set up their identification in the manufacturer field XD)
Check the constant value : android.os.Build.MANUFACTURER
I'm really interested to know more in this topic too so any more information is welcome.
The chart was on drawable-hdpi folder.
I was doing simply this:
img.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
The height was not proper in MID 7510 doing so.
Setting height like this worked for both the tablets:
static int imgHeight = 0;
Drawable d = (BitmapDrawable) getResources().getDrawable(R.drawable.chart);
imgHeight = d.getIntrinsicHeight();
final ImageView img = new ImageView(getActivity());
img.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (imgHeight * 1.5)));
This is because 1 hdpi= 1.5 mdpi. So total height should be 1.5 times of image height.