I have coded the whole app and designed all the layouts in Relative Layout, but now I want to make it compatible with all the screen sizes.
Asked
Active
Viewed 1,359 times
-3
-
2use constraint layout. – Sohail Zahid Apr 28 '17 at 10:58
-
1. Use dimens.xml http://stackoverflow.com/questions/32860815/how-to-define-dimens-xml-for-every-different-screen-size-in-android – Vijay Bhosale Apr 28 '17 at 11:06
-
As @SohailZahid mentioned you can use Constraint Layout https://developer.android.com/training/constraint-layout/index.html – Karacago Apr 28 '17 at 11:13
-
@SohailZahid constraint layout was the easiest and the best option .. thankz bhai – Gaurav Rai Apr 28 '17 at 13:58
3 Answers
5
I would recommend using the percent relative layout
It offers the following attributes which you can use to set dimensions accordingly.
- layout_widthPercent
- layout_heightPercent
- layout_marginPercent
- layout_marginLeftPercent
etc.

Dishonered
- 8,449
- 9
- 37
- 50
0
In most cases Android will automatically resize your layout to fit the screen. However, if you want to ensure that elements will be placed the way you define them to be then use different layouts for different layouts for different screen size. The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra-large screen should go in layout-xlarge/. Android documentation

Jan Stoltman
- 394
- 3
- 15
-
How to call the specific layout depending upon Screen-size ...I mean how to detect the Screen-size ..any pre-defined function for that? – Gaurav Rai Apr 28 '17 at 11:11
-
0
Try assigning weights to UI components. Works like charm, not matter what screen size is
example
<LinearLayout
android:weightSum="2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:text="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:text="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

Kiran Koravi
- 164
- 2
- 11