Supporting multiple screen is most important thing is android i think.We are doing some view different size.I know it is basic but i am curious about that.
For example i do a Edittext and i give width 200 dip for 480X800 screen.When i run this project 240X320 screen it will seen too big.We can fix this problem image with the drawable folder but how can we fix it view this problem?I know we can give wrap_content but when we give dip it is bad? When we give dip what is best effort from scale?
THX.
Just like with drawables, you can create different folders with layouts for different screen sizes.
As long as you keep the names of the files consistent across the folders, Android will manage picking the right one automatically.
Just create folders such as:
res/layout-small
res/layout-medium
res/layout-large
res/layout-small-land (incase you want landscape mode as well)
However, this does mean you will need to manually make adjustments for all screen sizes. Like in your example of the EditText, you will need to manually set the size to 100dp for example in the small screen layout.
The best way is to use wrap_content, fill_parent.
You can see layout_weight parameter of linearlayout where you can give value in %. But remember to give ur height or width as 0dp when you are using layout_weight.
Related
I already read a lot of threads on stackOverflow but I didn't find what I was searching for. I already read too the official documentation but I steel have some questions.
I'm trying to insert some image in my application and I'm trying to make the layout_width to the image equals to the width screen size (in portrait).
So I make many different size for the same image and I put them in
drawable-ldpi, drawable-hdpi ....
But when I'm trying my image on the emulator (hdpi) it works fine, but when I'm trying this on my tablet (hdpi too) the image don't get all the width screen.
I would like to know if I have to do multiple drawable about the screen size ?
and so then what about the drawable about the dpi ?
I know it's possible to put some vector image but I would like to know if I can choose the layout_width like this: android:layout_width = screen width.
and why is it so important to set the density ? A big tablet can be in mdpi et a phone on hdpi... what is so important in the density ?
Try using android:layout_width = "match_parent" in your layout.xml this will set the width of your main layout or parent layout to stretch from one side of screen to other side of screen. setting android:layout_height = "match_parent" and android:layout_width = "match_parent" will spread the layout over whole screen (top to bottom and left to right).
AND TO SAVE TIME AND EFFORT of creating different sizes of same image and icons,
you can use Android-drawable-importer plugin. With this plugin, import just 1 image and it will create different sizes (small,large,xlarge,xxlarge etc) automatically by it self.
Thank's for answer. I'll try to use this extension and see.
Edit:
It works fine but it make different image size only for the resolution (hdpi,mdpi ...) but it can't make different image size for the screen size ? Maybe I didn't see where I have to go ...
Do you know what I have to do ?
And I have a new questions: What is the vector image extension I must use in my projects ? I have .EPS and .AI but the plug in don't see theme in the search folder window. Do you know what is the step who can resolve it ?
I am doing a lot of work about android layout I still can't create a layout working in every phone. I am not sure about best the way to create a layout so correct me if I am wrong . There are three things to keep in mind :
Screen px (resolution, for example 1080x1920 px)
Screen dimension "inches"
Screen density dp or also called dpi ( dp is a virtual resolution, it's correct?)
To draw a layout working in every phone (my app will works for phones) do I have to create a directory "layout-kindofdensitydpi for every screen density (layout-ldpi,layout-mdpi,layout-hdpi,layout-xhdpi,layout-xxhdpi,layout-xxxhdpi) and draw "manually" or do I have to do something else?
I did a test, I created these 6 directory and drew manually for every resolution. It requires a lot of time, also device with a resolution of 768x1280 my app doesn't respect what I drew, for example spaces aren't respected, the collocation of elements doesn't result correct and frame layout with ImageView inside isn't scaled.
What I have to do? In some Android books isn't mentioned that elements could not resize and usually them explain how to put some text or image without analyse resize in every device.
Thanks in advice
First you should find the appropriate layout type for your UI (RelativeLayout or LinearLayout). Sometimes using a good layout(or nested layouts) can make the UI look good on every screen. I prefer LinearLayout cuz I can simply set layout_weight for components.
Then set different sizes in dimens.xml file for different densities or screen size buckets. Like this:
And you can also use match_parent or wrap_content
Don't forget to set the screen orientation of your activity if it doesn't need to rotate. Having one orientation makes it much easier to design.
If you couldn't make a good layout using tips above you should create multiple layouts to fit every screen size or density (Screen size and density are two different things).
You should find the best way to determine your screens according to.
Screen size bucket (small, normal, large, and xlarge) picks a layout that fits the screen (or the closest), density bucket (ldpi, mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi) picks a layout according to the density ,or the smallest width (I think it's almost the same thing as density).
480dp is the sw of these two devices
You can make layouts for different screen orientations too.
I don't like creating layouts for different screens for some reason. One of them and the most important is that sometimes same screen sizes have different densities and it makes it hard and time consuming. To create a layout and you should also provide a lot of pictures.
Use
android:layout_width="match_parent"
android:layout_height="match_parent"
to the outer layout to get access of the full screen of the device.
Also, if there are no changes in your UI then you don't need to create different layout folders.
Refer http://developer.android.com/training/multiscreen/screensizes.html
You should have a look at
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screensizes.html
http://developer.android.com/training/multiscreen/index.html
I would suggest using layout-swXXXdp or layout-large etc instead of layout-KindOfDensitydpi
Create your relative layouts using RelativeLayout and use the weights of LinearLayout. Don't hard code any of the positions in the layout
What is the correct way to position controls in a RelativeLayout so that it displays the same irrespective of Device Resolution.I guess this is clear enough,If we use dp values in giving margins like android:layout_marginTop="17dp" It displays at different places on mdpi,xhdpi,hdpi.
Can someone give a full fledged guenine solution to it? Thanks
You should have different layouts for different screen sizes. For example for xhdpi screens you create layout-xhdpi folder and put layout.xml for xhdpi screens in there. The same for other screen sizes. There is no way to have one layout looking exactly the same on all displays.
See this: http://developer.android.com/guide/practices/screens_support.html
Hello android designers,
1-I have been wondering. Is it a good design approach to always use RelativeLayout and layout weights so that it work on multiple screen sizes without the need of having different layout folders?
2-Another question, I have a textview with size 12sp (scaled pixel) that looks good on medium screens but when I run it on large screen it looks really small. Shouldn't it be scaling accordingly? According to android best practices,using sp is good for scaling. I see it really problematic, to try to guess the correct number for each screen size as 12sp already took mnultiple guesses till I found that this would suit my application relative to other components
Please share your experience/advice. I am always confused about it
Thanks
One think to keep in mind about Dip (density independent pixels) and sp (scaling pixels (?)) is that they are tuned for medium density screens. With the introduction of high-density devices, these standards are going to have to be revised by Google.
With that said:
I have better luck using RelativeLayouts and weights than I do with using explicit DIP. I usually use LinearLayout instead of RelativeLayout-- but as long as elements are positioned relative to eachother instead of absolutely it doesn't quite matter if it's a RelativeLayout or a LinearLayout or something else entirely.
That is what happens- keep in mind 12sp is "small", and it will be "small" text on large screens. Instead of scaling the font, scale the TextView-- for example, center your text in your TextView and have your TextView take up half the screen (using Weight, no matter the screen size).
Remember that things will look different on different screen sizes-- the trick is to make sure it looks good on each size, as opposed to identical.
i par my knowledge Linerlayout and relative layout is best for design xml in android.
Both are use diff purpose suppose
case 1: if there is large data eg from db and you want to display it on layouts then use Scroll view around layouts.
case 2: but in diff case like for design signup xml then use linear layouts and weight.
so layout is not change in any screen size of android device.
i hope this help may you.
It's better I think to create different layouts. In landscape mode on big screen for example you may want to display more elements to fill the space. As edthethird stated its better to have it look good instead of identical.
When I try to run my project on LG Android Mobile then there is no alignment issues come with this device it is a 3.2 HVGA but when I try to run it on Motorola it is a 3.7 WVGA then it gives complete layout alignment issues so can you tell me suggestion to implement layouts uniquely to every device.
I don't know is it possible or not to make a unique layout design for all devices.
You can't create custom layouts for different devices, but you can for different screen densities and sizes, Supporting Multiple Screens has all of the information you should need.
You can create custom layouts by reading the device layout screen like this
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
There are two ways you can create your layout. You can create your own algorithm that checks the difference between the resolution you have made your layout for, and gets the difference for the current screen size, and adjust all those values progmatically (long and tedious, but DEFINETELY will work on all devices)
Or, you can define a layout for each of the common devices in your layout folder. This requires alot more space and time though.
Sometimes back I was having this type of problem. Because I was using Pixels as my unit to specify height, width or any layout specific dimensions. But I changed those px to dp and it worked for me. I got same layout for all the screens. Hope if this may help you anyways...
Here is a quick checklist about how you can ensure that your application displays properly on different screens:
1.Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file
2.Do not use hard coded pixel values in your application code
3.Do not use AbsoluteLayout (it's deprecated)
4.Supply alternative bitmap drawables for different screen densities