Bahu
Bahu

Reputation: 1596

Responsive design for all android devices

I am using two different methods to achieve responsive design in android devices

Method 1. I used different dimens.xml in different folders like

values-hdpi
values-ldpi
values-mdpi
values-xhdpi  
values-xxhdpi

Method 2. I copied all my layouts to

layout
layout-large
layout-small
layout-xlarge

folders and given different heights, widths and other

When I use the first method I am not getting the correct responsive design and when I use the second method I am getting the correct design but it increasing the application size.

So, please tell me the best process to achieve 100% responsive design other than my two methods

Upvotes: 8

Views: 3869

Answers (2)

Kristiyan Varbanov
Kristiyan Varbanov

Reputation: 2509

You can use google library PercentRelativeLayout with this library you can set width, height and margin of your views by percentage which is great because in all screen they look the same and of course it is not hard to code it. Here example:

<android.support.percent.PercentRelativeLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
     <ImageView
         app:layout_widthPercent="50%"
         app:layout_heightPercent="50%"
         app:layout_marginTopPercent="25%"
         app:layout_marginLeftPercent="25%"/>
 </android.support.percent.PercentRelativeLayout>

you must add this line in your build.gradle

dependencies {
    compile 'com.android.support:percent:23.2.0'
}

Official documentation by Google https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

Hope this help for your case!

Upvotes: 1

Gabor Novak
Gabor Novak

Reputation: 286

I usually go for the values, values-large, ... folders and put dimens.xml files there, where I specify the sizes for each screen size category. The values is the "fallback", it contains the default value if I don't specify any for a specific size category. In the layouts I use it like this:

android:width="@dimen/width_for_this_view"

Defined in the values/dimens.xml:

<dimen name="width_for_this_view">30dp</dimen>

You can define different sizes for different values (large, normal, small, ..) folder.

Upvotes: 2

Related Questions