ClearCode
ClearCode

Reputation: 47

Android layouts size and resize

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 :

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

Upvotes: 1

Views: 8874

Answers (3)

user2604179
user2604179

Reputation:

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:

enter image description here

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).

480 is the sw of these two devices

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.

Upvotes: 2

harrane
harrane

Reputation: 969

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

Upvotes: 0

Pooja
Pooja

Reputation: 2467

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

Upvotes: 1

Related Questions