WearOs using the the smallest width qualifier on layout doesnt work - android

I am trying to get different sizes for different display sizes and followed Use the smallest width qualifier logic but on WearOs 2.0, it doesnt seem to be working.
Basicallly I created 2 values folder as below. I am testing with Samsung Galaxy watch classic 4 46mm and it has larger than 350dp. So Screen width bigger than 250dp should use layout in the screenshot but always takes the default layout. Why is this? Is that logic not working for WearOs?

Related

Layout Issue on Small Screens

I'm working on a Android App. Layout working fine on every device except where device screen size 480x800 & less.
How can create separate layouts by only targeting that screen size or less?
I'm already tried layout-hdpi, layout-small-hdpi & layout-normal-hdpi since phone like Nexus S, Nexus One are in hdpi category. But when I create separate layouts like layout-hdpi those layouts are affecting phone with bigger screen like Pixel, Pixel2, Nexus 5 etc.
Thanks in Advance
Phones (as opposed to tablets) tend to come in about three size groups (as far as Android resources are concerned): those with smallest width of 320dp, those with 360dp, and those with 410dp. The resources framework gives you a way to target any device larger than a certain width, so the correct technique is to put layouts for small screens on the default folder, and layouts for larger screens in one of the qualified folders.
Since it sounds like your layouts currently work well for anything 360dp or larger, you can make two layout directories:
res/
layout/
layout-sw360dp/
Put the special layouts for the small screens inside res/layout/ and put the “normal” layouts in the other directory.
Its not easy but you can also specify layouts based on the smallest width and you you supply the numbers. You can get more detailed and separate layouts that way however in my experience you will still run into that problem from time to time. In my current project using this method I have specific folders for W360 and W400 to deal with smaller devices for one specific screen.
https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
What you are looking for, is a layout bucket with the smallest width qualifier.
A layout with a set smallest width will be active, unless the smaller of the both dimensions (width or height) is lower than a certain value you can choose.
So, when a device has a smallest width below some value X it will use the default layout, when the value is X or more it will use the defined smallest width layout.
To create such a layout file in Android Studio, you wanna right-click your layout directory, click on new -> Layout Resource File and select the Smallest Screen Width qualifier from the list of available qualifiers. Now you need to specify your smallest width, which in your case should be slightly above 480dp. Give it the same name as your current layout file. Place your code for devices with a smallest width above 480p here. Now change the code in your other layout file, without the smallest width qualifier, to support smaller screens.
For further reference take a look at the official Android Developer page.

Why layout is disturbing even using width in dp Android

I have created a demo application in Android using Nexus 9 2048 X 1536
I have added an EditText and assign width as 1000dp it is working fine in Nexus 9 Emulator. But When I change the Emulator as Nexus 5X 1080 X 1920 to test the dp purpose, Then the EditText goes out of the layout and shown about half of it.
Why it is happening even I assign the width in dp. It should adjust the width by screen-resolution.
It should adjust the width by screen-resolution.
No, it does not. dp will adjust the width by screen density, not screen resolution. You asked for it to be 1000dp wide, and so it will be 1000dp wide, regardless of screen resolution or screen size.
You have a few alternatives:
1) The right and recommended one is to make different layouts for different screens. For this alternative see Supporting multiple screens
2) Another alternative I used to use before ConstraintLayout was to make everything proportional. When the app starts I take the meassurement of the Display and layout everything based on that. This is done mostly programatically not using the xml layout file.
3) Use the new ConstraintLayout from the support library. Using this layout you can constraint your widgest relative to each other and or to guidelines you can add to your layout to delimit sections of it. Your widgets that need to adapt will mostly have a width of 0dp or wrap_content and the constraints will take care of resizig them accordingly.
Using ConstraintLayout

How to make layout compatible with different android devices in android studio?

I am designing an app with a .jpeg background and with text views on particular places on the screen. I designed this for my nexus 6 and used dp for the widths and heights of text views and margin-left and margin-top. What my understanding of dp is that it changes with every device according to screen size and density. So it should work on different phones according to the value of dp for them.
But this is not the case. When I run that app on a different phone (nexus 5) the layout is all messed up. I tried using the different resources and qualifiers for different screens (large, small, normal). But the problem still prevails. The app considers both nexus 6 and nexus 5 as large screens. How do i fix this?
this is not the best solution i guess.
i guess your layout is just on the layout folder. i don't know if the first device you tested the layout is large or small but what you should do is create another folder named layout-sw600dp. this folder is used by tablets. the folder layout is used my phones and smaller devices. you could also create the layout-land and layout-sw600dp-land folders for the landscape orientation.
dp do change depending on the device but if your layout gets messed up then i guess the layout called by that device doesn't fit its resolution. i guess dp becomes smaller if the device is bigger and vice versa.

Developing Application For Tablets | Android

I have developed an application for Android Smartphones (including 7 inch tablets and Notes) , i forced the application to be run in vertical (by AndroidManifest.Xml)
Now i want to develop the same application for tablets ( specially for 10.1 inches) :
it will be the same APK , or its better to Create another APK ?
Is there anyway to find if device is tablet or not? (size of screen or something)
if it will be same APK , how can i force the app to stick on Vertical for Smartphones and stick on Horizontal for Tablets? (
Meaning if app is running on tablets it will never rotate to
vertical and vice versa for smartphones )
how can i define layouts for horizontal ?!
if anyone got special experience on doing this please share it with me
I would like to give you some suggestions.
it will be the same APK , or its better to Create another APK ?
It should be a single app.
if it will be same APK , how can i force the app to stick on Vertical
for Smartphones and stick on Horizontal for Tablets? ( Meaning if app
is running on tablets it will never rotate to vertical and vice versa
for smartphones )
For layout issues concider this. which should give you some basic idea about how to acheive it.
how can i define layouts for horizontal ?!
For horizontal layouts you can define a seperate layout. You check for the screen size or whatever stuffs which proves for horizontal layout and set the layout.
if anyone got special experience on doing this please share it with me
I have followed it by using the screen sizes and I have used the layout depending on the size. Have a look at this explains somethings to you.
Edit :
Same applies for the vertical layout as well. That is have a vertical layout defined.
For Horizontal use dp. Know about it with above first link. There you can have it like below.
Density-independent pixel (dp) A virtual pixel unit that you should
use when defining UI layout, to express layout dimensions or position
in a density-independent way. 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.
At runtime, the system transparently handles any scaling of the dp
units, as necessary, based on the actual density of the screen in use.
The conversion of dp units to screen pixels is simple: px = dp * (dpi
/ 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical
pixels. You should always use dp units when defining your
application's UI, to ensure proper display of your UI on screens with
different densities.

Different sizes on 2 devices, even if I use "dp"

I've 2 tablets:
1 Samsung Android 3.0
DisplayMetrics {density=1.0, width=600, height=976,
scaledDensity=1.0, xdpi=161.55031, ydpi=155.51021}
1 Low cost device, Android 2.3.3
DisplayMetrics {density=1.0, width=480, height=800,
scaledDensity=1.0, xdpi=160, ydpi=160.42105}
If I use different layout for each screen size, both devices says they are large-long and mdpi, so I can't distinguish them by using layout folder names... The problem is:
I use a TextView with textSize="20dp"
In the firse device, text width is half of the screen, in the second device is bigger (80% of the screen width). Why? I expect that both devices display text in the same way if I use dp (and not px). I tried also with sp but nothing changes...
(I used TextView as example, I've the same problem with all elements in the layout: button sizes, ...)
I would try to use layout folder names like "layout-w600dp" or something else introduced in Android 3.2 but this is not the case.
I know I can change element dimensions by code in onLayout() but I don't want to do that...
Any suggestion?
Update
I solved my problems with layouts using themes: Activate a specific dimens.xml at runtime
The android documentation on Dimention say this
The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion
So it's totally ok what you see
You can achieve 50% of the screen using LinearLayout weigth..Refer this

Categories

Resources