I want to make my view Responsive, look at following images.
1st Image is what it should ideally look.
But when I change the screen size, it changes the size and alignment. I want fixed size views over all screens.
You should follow Step by Step approach .
Android runs on a variety of devices that offer different screen sizes
and densities. For applications, the Android system provides a
consistent development environment across devices and handles most of
the work to adjust each application's user interface to the screen on
which it is displayed.
Read Supporting Multiple Screens .
To optimize your user experience on different screen sizes, you should
create a unique layout XML file for each screen size you want to
support.
Read official guideline about Supporting Different Screens .
Read Build a Responsive UI .
Related
I designed an app with dp unit. I also used RelativeLayout. I designed app while Pixel 3XL screen selected like this. After i finished the design i changed the screen to the Pixel like this. Now my design looks bigger.Look the red line. Not equal to the Pixel 3XL. I want my app to look the same on every phone. Thank you.
From Document:
Android devices come in all shapes and sizes, so your app's layout
needs to be flexible. That is, instead of defining your layout with
rigid dimensions that assume a certain screen size and aspect ratio,
your layout should gracefully respond to different screen sizes and
orientations. By supporting as many screens as possible, your app can
be made available to the greatest number of users with different
devices, using a single APK. Additionally, making your app flexible
for different screen sizes ensures that your app can handle window
configuration changes on the device, such as when the user enables
multi-window mode.
This page shows you how to support different screen sizes with the
following techniques:
Use view dimensions that allow the layout to resize Create alternative
UI layouts according to the screen configuration Provide bitmaps that
can stretch with the views
https://developer.android.com/training/multiscreen/screensizes
https://material.io/design/layout/responsive-layout-grid.html
Try using constraintLayout if you want to build responsive designs.I have tested it on multiple devices and google also recommends it.Go through the link.
https://developer.android.com/training/constraint-layout
I made a calculator app and used density independent pixels to create the layout, place the buttons and so on. Yet on a tablet emulator it doesnt display correctly, it only takes about 1/4 of the screen. On my phone(800x480) everything is ok. How can I adress this issue?
You'll need to provide additional layout folders for the different screen sizes so that the Android system doesn't use the same one by default, resulting in the behavior you've described.
This is accomplished by adding layout folders with size specifiers such as: small, medium, large and xlarge.
layout-small is an example.
So, to be clear, you're adding additional folders for the different supported screen sizes. You'll then add a layout of the same name to each folder you add. The system handles the headache.
You would then alter the layout to achieve the best results. Note that it is common practice, when dealing with larger screen sizes, to provide more content on a single screen as opposed to blowing everything up. If your app can benefit from that, it looks better than having obscenely large buttons stringing across the screen, IMHO.
For a complete run down, please refer to Android Documentation.
There is a solution to resize automatically the views of my android app?
I've optimized it for 7" screen.
But now I want to use it on 3.2" screen and it's looking horrible!
I've you got some ideas or I have to do it manually?
This would be the first stop I would recommend:
http://developer.android.com/guide/practices/screens_support.html
This document explains the screens-support features provided by the platform and how you use them in your application. By following the practices described here, you can easily create an application that displays properly on all supported device screens and that you can deploy to any device as a single .apk."to any device as a single .apk.
and check this pdf: http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf
Define sizes/dimensions in the dimens folder, and set sizes to your Views programatically through Java.
Or, you could set the size based on some ratio, according to the screen size. I mean, you can calculate the width/height of the screen during runtime and make the dimensions of your view screenwidth/x.
Please read this tutorials from Android developers:
Supporting Multiple Screens
Designing for Multiple Screens
I have around 10 activities in an app and around more than hundred images. Now need to provide support for multiple screens of diff sizes and densities. If I need to create for small,large and xlarge sizes even though it will be customization of 30 more activities rest aside diff densities for a specific size :O Is there any way I can stretch the whole layout depending on the size and densities, I mean what is the best way to solve this problem. It must be a very common problem but I am missing something here. I read the android dev. screen support doc but still confused. Any ideas? Thanks for your help.
It's hard to give an answer specific to your project, but in general Android does a good job of this all by itself. All layouts will automatically scale if you haven't specified fixed dimensions (ie using px instead of dp). When it comes to fullscreen images (background and the like) it is best if you provide several resolutions (in the drawable-mdpi, drawable-hdpi etc) folders. You may also have to look at the scaleType for an ImageViews you may have.
Read through the official documentation on how to support multiple screen resolutions. It provides all the information you need and it goes into detail on how to provide different layouts not only for different screen resolutions, but also for different screen orientations and things like smallest width etc (for tablet specific layouts)
I have developed an Application for android compatible devices mostly covered mobile phones, but when I am running it on Tab the screen size will get changed and all the content on the particular screen not behaving properly, As I have designed it keeping in mind that it should be compatible with mobile phones
Now, I just wanted to run my app on tab with the same screen size as it is showing on my mobile phone, without stretching of screen size.
What should I do to achieve it ??
Thanks
This isn't really a question that can be answered with a simple "set this style flag on your activity and you'll be on your way!" kind of answer. To get an app to scale properly across multiple screen sizes, you really need to start with the layout design itself. Android will try to keep your components the same size across different screen densities, but if you just leave it at that it still won't look very good because you'll have lots of empty or poorly utilized space.
The platform documentation and design guidelines go fairly in-depth into screen size compatibility and making a single app work and look good across all screens, large and small. In particular, I recommend reading the following articles:
Supporting Multiple Screens
Supporting Different Screen Sizes
Supporting Different Screen Densities
It'll take some work to make your app look and work great on tablets and phones (with just one APK) but if you want to make a good experience on a tablet without the hassle of maintaining two separate codebases, it's worth learning.
Pay particular attention to size qualifiers, which allow you to load different resources (drawables, layouts, etc) based on screen size (small, medium, large, x-large). That way you don't have to just blindly scale everything up on a tablet... if appropriate, you can tweak your layout on a tablet to make the experience more user-friendly.
Additionally, I recommend looking into Fragments, which allow for lots of flexibility in your UI across tablets and phones while not requiring you to have to write a bunch of code for differing layouts. For example, instead of having a newsreader that has two screens, one to display a list of articles and one to display article content, you can use Fragments to have a side-by-side, two-pane view of articles and content on tablets, while still having two separate screens on phones, which are more narrow. Fragments and FragmentActivities make this much easier to write and maintain.
You could set layouts width and height in pixels.
It probably isn't the only way but it's what comes to my mind right now.