software buttons height - android

How I can calculate height of software buttons (like in galaxy nexus or razr motorola hd) ?
Personally, I suppose that DisplayMetrics.heightPixels attribute is height of all screen without software buttons height and with height of status bar.
Hence, software buttons height = specification height - DisplayMetrics.heightPixels.
Exemple for nexus 7:
75(soft button height) = 1280(spec height) - 1205(DisplayMetrics.heightPixels)
Im right ? please confirm.

My assumption is right.
to generalize question and prove it, here manual measurement what I have done on telephone and tablet from screenshots :
SOFTWARE BUTTONS HEIGHT
samsung galaxy nexus
portrait: 48 dp
1280 - 1184 == 96 px == 48dp xhdpi
landscape: 42 dp
1280 - 1196 == 84 px == 42dp xhdpi
( attention!: in landscape, this is not height but width of software button placed on right side of screen)
on nexus 7
portrait: 56dp
...
landscape: 48dp
...

Related

Android spacing issue in same resolution devices 1080x1920

I am designing screen from Zeplin. (Zeplin provides each item attributes in dp)
Following is the horizontal recycler view design example with 4 items from Zeplin.
360 dp means 1080 for xxhdpi devices
I am testing my code on two 1080 devices with different dpi
Samsung c5 [1080 x 1920 pixels, 16:9 ratio (480dpi)]
Nexus 5X [1080 x 1920 pixels, 16:9 ratio (420dpi)]
I am facing spacing issue in Nexus-5x, the Zeplin design works great
on Samsung-c5.
Samsung-c5 result
Nexus-5x result - spacing issue in horizontal recycler view
QUESTION:
Why the design in different on same resolution (1080x1920) devices (different dpi). How can I make it look same on each and every device like facebook does with its status
Similar Questions:
How to use 1080x1920: 420 dpi - Android studio
Android xxhdpi, 420 dpi and 480 dpi
XXHDPI Layout different on different XXHDPI devices
Sol1 - Calculator app different layout on same screen size but different DPI (420 DPI vs 480 DPI) - Android Developer
Sol2 - Android layout folders for different screen sizes
Placing dimens in values-w410dp worked, as mentioned in the answer here

android screen size not scaling

I'm trying to support multiple screen sizes but I'm obviously missing something
I'm testing between a Samsung Galaxy Tab Pro (10.1 Tablet) and Samsung Note 3 (phone/fab)
DisplayMetrics WidthPixels HeightPixels Density DensityDPI
Tab Pro reports 2560 1600 2.0 320
Note 3 reports 1920 1080 3.0 480
I have all the layouts in /res/layouts and They all start with
RelativeLayout match_parent for layout_width and layout_height
My AndroidManifest.xml has
Ideally I would like to support screen resolutions of 1024 x 768 and larger
Which both the Note 3 (at 1920x1080) and Tab Pro (at 2560x1600) are
On the Tab Pro everything lays out the way I would like
On the Note 3 you are only seeing the upper left corner of the screen
It is almost as if the Tablet Layout has been cut in quarters
Y X
X X
And the Note 3 shows the Y only while the Tab Pro shows it all
Please help ? ?
Thanks in advance

Trying to define which layout should a device use

I'm trying to understand which layout uses which device.
For instance, I've different layouts:
layout
layout-sw600dp
layout-sw720dp
Nexus 7" (800x1280) uses layout-sw600dp
Samsung GTp3100 7" (600x1.024) uses layout-sw600dp
Samsung Tab 10.1 (1280x800) uses layout-sw720dp
Sony XPERIA S 4.3 (1280x720) uses layout
Can you guys explain "with your words" why isn't XPERIA S using sw600dp or sw720dp?
SW != smallest width? So smallest with from XPERIA S is 720. It should be using sw720 or sw600, right? Or am I wrong?
I've read tons of documentation, but can't understand why is this happening.
Thanks a lot.
The Smallest-Width qualifier refers primarily to screen size and not the physical pixels.
Using sw720dp for example means the device must have a minimum screen width of 720 dp (device-independent pixels) - this isn't about 720 physical pixels. From the documentation...
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen.
The physical width of the Sony XPERIA S 4.3 is 2.5" but I don't know how much of that is the actual width of the screen.
Let us pretend for the sake of calculations that the screen covers the full width...in this case to calculate dpi for width we simply use 720 / 2.5 = 288dpi.
From the documentation for dp...
The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160).
Rearranging the formula above to calculate dp we do this...
dp = px / (dpi / 160)
...this gives us the width in dp (and a necessary Smallest-width qualifier) of...
720 / (288 / 160) = 400dp
In short the answer is, the Sony XPERIA S 4.3 may have a high-density screen (for its size) but it isn't a large screen.

Discovering the true screen size (in pixels) for Android devices which have a Software Navigation Bar

I need to be able to know the exact size of the screen excluding the Software Navigation Bar before hand. I'm using the andengine to create a game.
We wanted to fully support the new Nexus line (4, 7 and 10)
According to this page, which many have pointed out, the size of the Software Navigation Bar should be 48dp.
Then using the information on this excellent stackexchange post I gathered the formula for calculating the size of the Software Navigation Bar should be: px = dp * (ppi / 160)
According to the official site the Nexus 7 has a 216 ppi screen.
The Software Navigation Bar should then be: 48 * (216 / 160) = 64.8 ≈ 64px
We have a Nexus 7 tablet and the Software Navigation Bar is 75px.
This means that either the ppi value is (75 * 160) / 48 = 250
or
the dp size is in fact (75 / 216) * 160 = 55.555... ≈ 55dp
So which is it?
Furthermore the 4.2 Android SDK comes with some premade AVDs. Included among them is the Nexus 7. There the size of the Software Navigation Bar is reported to be 64px...
I'm not asking for the sizes of these devices, I can just google (or search stackexchange) for those numbers. Is it not possible to be sure of a device's screen size without purchasing that device?
[edit]
I thought I should add that I'm getting the screen size with the following method:
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics screenSize = new DisplayMetrics();
display.getMetrics(screenSize);
CAMERA_WIDTH = screenSize.widthPixels;
CAMERA_HEIGHT = screenSize.heightPixels;
Better later then never. I was looking for something like this, and second link was this question, but first was
http://www.emirweb.com/ScreenDeviceStatistics.php
For example
Nexus 4
1280 x 768 px (640 x 384 dp) / xhdpi / Normal screen
Portrait Details
Navigation bar height: 96 px (48 dp)
Title bar height: 96 px (48 dp)
Status bar height: 50 px (25 dp)
Content View: 1038 x 768 px
(519 x 384 dp)
Landscape Details
Navigation bar width: 84 px (42 dp)
Title bar height: 80 px (40 dp)
Status bar height: 50 px (25 dp)
Content View: 638 x 1196 px
(319 x 598 dp)
I believe it can be useful.
Software navigation bar height is 48dp.
96px # xhdpi /
144px # xxhdpi /
I don't think you would find it #hdpi phone but it would be 72px.
Notification bar height seems to have 25dp (Android 4+).
38px # hdpi /
50px # xhdpi /
75px # xxhdpi
It gives you:
1134px # xhdpi (#1280px height) / *1701px* # xxhdpi (#1920px height) /
of available space.

How to set android layout to support all screen sizes?

I am developing a program on android version2.2. I have read many documentation on supporting multiple screen sizes but still confused. I designed a layout file, that supports for large and normal screens, when am trying it with small screen it is not adjusting the layout to fit the screen. I used this code in the manifest also.
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"
/>
The image for the small screen is here.
How can I set the screen that compatible with small screen? Somewhere I found by using the folder "layout-small" but if I use this, the project size is increasing, I don't want that, so can any one suggest me the best way to do this?
Solution for all screen and support all layout.
Icons:
mdpi hdpi xhdpi xxhdpi xxxhdpi
Launcher Icons (App Icons) 48 x 48 72 x 72 96 x 96 144 x 144 192 x 192
Action Bar,Toolbar,Tab Icons 24 x 24 36 x 36 48 x 48 72 x 72 96 x 96
Notification Icons 24 x 24 36 x 36 48 x 48 72 x 72 96 x 96
Background Image Resolution:
ldpi: Portrait: 240 X 320px. Landscape: 320 X 240px.
mdpi: Portrait: 320 X 480px. Landscape: 480 X 320px.
hdpi: Portrait: 480 X 800px. Landscape: 800 X 480px.
xhdpi: Portrait: 640 X 960px. Landscape: 960 X 640px.
xxhdpi: Portrait: 960 X 1600px. Landscape: 1600 X 960px.
xxxhdpi: Portrait: 1280 X 1920px. Landscape: 1920 X 1280px.
Drawable Folder:
res/drawable (default)
res/drawable-ldpi/ (240x320 and nearer resolution)
res/drawable-mdpi/ (320x480 and nearer resolution)
res/drawable-hdpi/ (480x800, 540x960 and nearer resolution)
res/drawable-xhdpi/ (720x1280 - Samsung S3, Micromax Canvas HD etc)
res/drawable-xxhdpi/ (1080x1920 - Samsung S4, HTC one, Nexus 5, etc)
res/drawable-xxxhdpi/ (1440X2560 - Nexus 6,Samsung S6edge).
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Layout:
Portrait:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-large/main_activity.xml # For small tablets (640dp x 480dp and bigger)
res/layout-xlarge/main_activity.xml # For large tablets (960dp x 720dp and bigger)
res/layout-w600dp/main_activity.xml # For 7” tablets or any screen with 600dp
# available width (possibly landscape handsets)
Landscape:
res/layout-land/main_activity.xml # For handsets in landscape
res/layout-sw600dp-land/main_activity.xml # For 7” tablets in landscape
Refer links:
Different resolution support android
https://developer.android.com/guide/practices/screens_support.html
https://design.google.com/devices/
Is there a list of screen resolutions for all Android based phones and tablets?
http://www.emirweb.com/ScreenDeviceStatistics.php
Most popular screen sizes/resolutions on Android phones
Please go through the following links. These might help you:
Supporting Different Screen Sizes
Supporting Multiple Screens
Supporting Different Densities
Supporting Tablets and Handsets
AFAIK, the only way to support all screens is by doing that folder bifurcation. Every XML file goes up to a few kilo bytes. So, size shouldn't be too much of an issue as such.
Yes i have got the cure to your problem, you are right i personally think that making layouts for every screen resolution is time taking and making your project size go big.
To make a layout that fits across all screen resolution i have implemented my own technique i.e setting width and height in terms of percentage
The Problem occurs when we set Views/Layouts with some constant width or height value lets say 100dp.
Solution is quite simple try to use match_parent so that the view fill up empty space or use weight and define every View relative to other Views this will help your layout to look good in almost every screen resolutions and at run time set LayoutParams of only those Views/Layouts that has some constant width or height in terms of Percentage.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/mLayout"
android:layout_width="280px"
android:layout_height="300px" />
</RelativeLayout>
Notice: I have used px for fixed sized layout's width/height because in LayoutParams layoutParams = new LayoutParams(int width, int height); the width and height take value as pixels
Here is an example code
final ViewTreeObserver mLayoutObserver = mLayout.getViewTreeObserver();
mLayoutObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
#Override
public void onGlobalLayout()
{
DisplayMetrics metrics = getResources().getDisplayMetrics();
int deviceWidth = metrics.widthPixels;
int deviceHeight = metrics.heightPixels;
float widthInPercentage = ( (float) 280 / 320 ) * 100; // 280 is the width of my LinearLayout and 320 is device screen width as i know my current device resolution are 320 x 480 so i'm calculating how much space (in percentage my layout is covering so that it should cover same area (in percentage) on any other device having different resolution
float heightInPercentage = ( (float) 300 / 480 ) * 100; // same procedure 300 is the height of the LinearLayout and i'm converting it into percentage
int mLayoutWidth = (int) ( (widthInPercentage * deviceWidth) / 100 );
int mLayoutHeight = (int) ( (heightInPercentage * deviceHeight) / 100 );
LayoutParams layoutParams = new LayoutParams(mLayoutWidth, mLayoutHeight);
mLayout.setLayoutParams(layoutParams);
}
});
I guess the code is pretty much self explanatory if any one still need help you can ask right away
Conclusion: If you need to set some constant width/height for your Views/Layouts always set value in px in layout file (i.e xml) and then programmatically set LayoutParams.
Suggestion: I think Google Android Guys should seriously think of replacing the dp/dip units to percentage.
Now to support different screen size is more easy! Use new size unit SDP.
SDP - a scalable size unit
An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
for text views please refer to ssp which is based on the sp size unit for texts.
https://github.com/intuit/sdp
Scalable DP (sdp) is the best solution to use. It will resize the widgets depends on the screen size. We can also apply this for text for different text sizes.
To add sdp to your project (Using Android Studio and Gradle):
add implementation 'com.intuit.sdp:sdp-android:1.0.5' to your build.gradle dependencies block.
for example:
dependencies {'com.intuit.sdp:sdp-android:1.0.5' }
try this one
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/myimage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
Try this library is awesome
implementation 'com.intuit.ssp:ssp-android:1.0.6'
Example
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign up"
android:textSize="#dimen/_16ssp" />
I'm not sure that the solution but I want sharing with you will work everywhere, it covers most of the area.
I've solve this problem by partitioning a screen by used LinearLayout and define its orientation (horizontal or vertical), layout_weightsum = 3 (3 is to divide a screen into 3 parts).
Then inside that Root Linear layout, I again take LinearLayout with layout_height = "0dp" (if you want vertical partition only otherwise layout_height = "wrap_content" and if you need horizontal then make layout_width = "0dp" and layout_weight =1 (1 is for 1 part of the screen you can also put the value in float like 1.2).
Can try this it helps me, maybe and hope will help you.

Categories

Resources