Android Wear resource qualifiers - android

I'm developing for android wear, and instead of using 2 different layouts (one for rect, and one for round), can I just use resource qualifiers instead?
For example, I have a layout file: activity_main.xml. It references pizza.png. can I make it so that the round watch (320x320) pulls the image from drawable-w320dp while the rectangle watch (280x280) pulls the image from drawable-w280dp?
Thanks

Update:
There are specific qualifiers as of API 23 (-round and -notround). Check out the official blogpost.
Original Answer:
No, I don't think so. There are no specific qualifiers for form factor (such as -round or -square) and the screen size in pixels is not the same across all square devices. For example, the Samsung Gear Live is 320x320 too.
Moreover, these values are in pixels, not dp as in your example, but this is a minor point.

You should use -nodpi for backgrounds, and -hdpi for rest of graphic files (for now, it might change in the future). There are no shape specific folders as that should be handled in StubView or by fitting content in by using for example BoxInsetLayout.

Related

Is there a function in Android Studio to automatically adjust the layout to the display size?

I'm in the process of creating a small questionnaire. Although all views are constrained, the individual text views overlap or slide to the edge.
So far I have only created the design for the layout and have not yet linked any functions with anything. When I display the layout on a larger display, everything is shown as it should be.
Can someone help me and tell me how I can design my layout so that it automatically adjusts to the display size?
I'm really new about programming in Android and don't know all the backgrounds I may have disregarded.
I tried to use the AutoSizeMaxText fuction but I'm not sure if I used it the right way.
As far as I know there is no such thing as an automatic function to support different screen sizes.
What you can do:
Use constraintLayout
Use match_parent and wrap_content instead of hard-coded sizes in your xml
Create different layouts for almost every (if not every) screen resolution:
ldpi, mdpi, hdpi, xhdpi, xxhdpi
Use stretchable nine-patch bitmaps for image resources.
Consider using fragments and double-pane structure for large devices
You may want to chek this library: https://github.com/intuit/sdp
and this one for text size: https://github.com/intuit/ssp
Don't forget to test it in as many devices with different resolutions and pixel density as you can.
You can check the official documentation for this issue: Android developers: Support different screen sizes

5.2'' and 5.0'' screen support on android devices

I have been struggling with this problem about a week and can not figure out how to make it work. I have some views on a screen. And one values\dimens.xml(sw320dp-xxhdpi) resource file. Also I have nexus 5.2 1080*1920 420dpi and nexus 5.0 1080*1920 xxhdpi. The layout appears differently on both screens. How to make it display the same on each device?
What resource file should I add (if it is any)?
How to add for example values\dimens.xml(1080*1920 420dpi)?
I think your layout is simply built as poorly scaling. Unless you have some very specific use case, you need to make sure your layout fills the area it is provided with regardless.
As for the resource folder, if you want to make sure the same layout file is used on large screens, it is enough to put it in the folder layout-sw360dp. If you have xxhdpi devices with the resolution 1080x1920, Android will select the same file for both since the smallest side will be exactly 1080 / 3 = 360 density-independent pixels.
How to make it display the same on each device?
In general it's impossible for all Android devices. I think best solution - using VectorDrawable or SVG format and scale vectors for each device.

Android layouts - images for the different screen resolutions and the same density

I want to show some images on the background that is also image. Say my background image contains an empty squares, and I want to show an apple image that must appear exactly in one of that squares.
I have a problems with the apple sizes, as the background scales and fits the screen, but apple image stays the same for the different resolution and the same density devices.
Say I have two ldpi devices with 240x320 and 480x800 resolutions. When I keep my drawable aple file in the drawable-ldpi folder, and use wrap_content for height and width (or fixed dp values) those 2 devices draw the apple with the same size, like it is described in the documentation.
The LinearLayout works slow when I stack them.
Using RelaytiveLayout I must programmatically resize the images which is also "not so good" solution I guess.
I've found a solution here https://github.com/intuit/sdp that maps the dp-s.
They set dimen-s for values-sw300dp to be
<dimen name="_10sdp">10.00dp</dimen>
and for values-sw480dp to be
<dimen name="_10sdp">16.00dp</dimen>
and so on for the different cases ...
So when I set the with of the apple to be _10sdp it means different dp-s for my 2 devices with the same density and solves my problem. Is it a good solution as it seems to be for me?
Is there any other easy ways?
This is indeed the recommended solution as you could see in the iosched github repository which is a generally good source of knowing whether something is a desired common practice at least according to Google since i know they spend a lot of time to create this code to reflect the best practices and obtain the new APIs
Your solution seems good, just as common solution, would be good to use folders described in documentation.
For your case, as easier solution I would suggest to not use an apple image separately and place it in background's square. You can have an image: apple in square, and place it on background wherever you want. An apple will always be in a square and you can avoid tiresome process of creating dimens for each configuration.

Supporting multiple screen size - Android

I am going to develop new application in Android. This application should only work in portrait (even for tablet). Also the UI and layout design should be similar on phones and tablet. We can't change the layout design for tablet as it has huge area to use. We have to stretch all the images to match phones. We can use nine patch. But I am little bit confused of using images in multiple drawables.
As per my analysis (may be wrong.. : ) ) the screens are divided into density and sizes. We can use the scaling ratio of 3:4:6:8. But this ratio is based on the density. But in my case I have to stretch the entire UI to fill the Tablet screen.
So what are the drawables that can be used for a app like this which can support multiple devices. And what are the screen sizes for which we have to design.
And this application needs nearly 100 layouts. So I am planning to maintain single layout and designing the layout using weight for each layout instead of using dimension.
Also if I used multiple APKs to support different screen size what are the drawables used to support
1. Small and Normal
2. Large
3. Xlarge
I just did something very similar. To stretch the app without creating new layouts I used dimensions set in XML
res/values/dimensions.xml
res/values-sw600dp/dimensions.xml -> 7+ inches
res/values-sw720dp/dimensions.xml -> 10+ inches
Dimensions are resources files:
<dimen name="default_padding">11dp</dimen>
You can increase the dimensions by about 30% in the 600 and 720 file.
Then simply used #dimen/default_padding in your layout and it will be scaled
Regarding images, either you make sure you have all your assets in all densities, or you set fixed size to you ImageView's and appropriate scaleType
Firstly, you do NOT want to create multiple APKs to support multiple screen densities. Android provides all of the framework you need to support everything within one build, you just need to create the right resource hierarchy drawables with your desired densities.
So what exactly do you need... based on your question the following:
portrait mode: you can specify this in each Activity declared in your AndroidManifest file using the following:
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="orientation" >
...
</activity>
NOTE: Per the Android docs, if you're targeting API >= 13, and you use the android:configChanges attribute you should also use the android:screenSize attribute to help specify size changes.
dimension sizes for various screens: as touched upon, this can also be handled in resources. This is your best way to use one common layout file but configure the layout for use on numerous devices. See http://developer.android.com/guide/topics/resources/more-resources.html#Dimension for how to use dimensions if you're unfamiliar
drawables: it sounds like this is the crux of your question. As you mentioned, using nine-patches will help you reduce your app footprint and fill in extra space (see here and here for more on nine-patches). The sizes you should support and the densities needed for those sizes are discussed in great detail in Android design docs, so much detail I could not even do it justice rehashing it here. I've provided links below to as many places as I could remember that this is discussed.
Good luck!
Here are links to Android design docs that you will find useful (some of which have been mentioned):
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
http://developer.android.com/training/multiscreen/index.html
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/design/style/devices-displays.html
In addition to the pixel density specific folders, you can specify screen-size specific folders
drawable/
drawable-large/
drawable-xlarge/
drawable-hdpi/
drawable-large-hdpi/
drawable-xlarge-hdpi/
drawable-xhdpi/
drawable-large-xhdpi/
drawable-xlarge-xhdpi/
So you could design scale appropriate graphics for the various screen sizes and densities. Please note that a give screen size category (e.g. "large") will only give you a rough idea as to the actual device pixel dimensions of the device, but you'll get good guidelines for min/max dp ranges.
For example, you might have a 100x100 image you want to display on phones (screen size "normal"), you'd create image assets at 100x100, 150x150, 200x200 for drawable, drawable-hdpi, drawable-xhdpi folders respectively. But on 7" tablets, i.e. "large" screen size devices, you might display this same image at 200x200, so your "drawable-large" folder assets would be 200x200, 300x300, 400x400, and on 10" tablets, i.e. "xlarge" screens, you might display the same image at 300x300, 450x450, 600x600, so these go in "drawable-xlarge-*" folders.
All the details are here:
http://developer.android.com/guide/practices/screens_support.html
First you need all the possible screen layouts
drawable
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi // phones like s4
drawable-xlarge
drawable-tvdpi // nexus 7 etc
drawable-xlarge-xhdpi //tablet like nexus 10
layout : for phone
layout-sw600dp
layout-sw720dp
then you need to put all use 9- patch images for buttons etc ... you can also make your custom drawable it would be easy and handy to work on ..Also you can take dpi for each screen by using switch and scale it the layout accordingly.
As, in one of my project I had used this technique for showing respective thing to each resolution device .
DisplayMetrics metrics = getResources().getDisplayMetrics();
int densityDpi = (int) metrics.density ;
switch (densityDpi) {
case (int) 1.5:
break;
case (int) 2: //1.75 will be 2 in INT.
break;
default:
break;
}
also keep all the values you are going to used for margin padding etc values-sw600dp for tvdpi tablet ,value-sw720dp for tablets
Last but not least keep all thing generic as much as you can and put it in drawable ..
I have seen some ppl who used background patterns of different dpi's and put it in respective drawable .. if there is such thing like pattern make your custom drawble and repeat it accordingly
that will save your time .. hope it may help you
In order to stretch all the images to match phones you can specify the image size using the sdp size unit. This size unit is relative to the screen size so it can fulfill your requirement.

Best way to implement design in Android Application?

I am currently developing an Android Application for a company who are set on having this type of design and targeting Hires devices however I have found that this is very difficult to do and on some hires devices buttons start to stretch.
Screen design here: https://skitch.com/aaronwardle/r7kwa/screen
A few people have recommended making the buttons into Nine Patch PNG files which help with the various screen layouts.
Should I try and get a new app design for this project, which fits all screens using standard controls, or do you think this is achievable?
Looking at stats the most common devices are small screen ones, so creating this application may have a limited audience.
If any one has any pointers on what I could do, i.e. could I make this for hi res screens and within the application have a different layout for smaller screens?
Thanks Aaron!
Your question is too generic to give a simple and quick answer. Furthermore, the layout you want to make is complex and very non-native-looking which complicates matters. Please make sure you read and understand the official docs on the subject from HERE. There is no replacement for that...
The main points that come to mind from that document are:
the <supports-screens> manifest item
Resource directory qualifiers for screen size and density. Appending stuff such as -small or -portrait allows you to create resources that are loaded only on a particular screen aspect, size or DPI. For example, you can create bigger images for bigger screens, or change the layout XMLs for portrait or landscape
Use 9-patch images to scale up rectangles (buttons).
Best practices (as recommended by Google):
Use wrap_content, fill_parent, or the dp unit, instead of absolute pixels
Avoid AbsoluteLayout
Do not use hard-coded pixel values in your code
Use density and/or size-specific resources
I know my answer is a bit generic, but then again, so is your question...
You have to use 9 patch png and also will have to make some changes in the manifest file, to make it screen resolution free. These are very less changes in the manifest file so would not be a trouble.
You can use 9 patch images as well as to design application for different resolutions, you can create different layouts for landscape and portrait.

Categories

Resources