Here is how you will build your app compatible for each and every screen size in the world.
1) Add a small entry in Manifest: The first and most easiest way is to write the following in your manifest file.
3) Create separate layouts: There are devices which have very high screen resolutions. The layouts made in the 'layout' folder cannot be applied for those as it won't look stunning. So in order to do so we have to create some extra separate individual layouts for those devices.
There are various ways to make your app compatible for all screen sizes. Here are some of the techniques described in easy way:
1) Add a small entry in Manifest: The first and most easiest way is to write the following in your manifest file.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
This will make your app's display fit to devices from small to extra large screens. Also it supports all densities.
2) Use weights and wrap_content & match_parent in layouts: In Android, weights are very important useful layout attributes. A weight is nothing but the percentage of area that needs to be covered. It works just like wrap_content & match_parent and automatically expands & shrinks according to the layout. Our job is just to specify the weight value.
Suppose you want to develop an app that has such a UI which should cover all the area of the screen proportionally as shown in the screen-shot, then weight does a big work as it suits for portrait as well as landscape screen orientation:
Here is how you modify your layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="3">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#9940fd"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#9965fd"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="3"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#9940fd"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#9965fd"/>
</LinearLayout>
</LinearLayout>
Here is the screen-shot how to make it.
No comments:
Post a Comment