Compatibility with different resolutions/inches
You can replace your fixed size (what you are currently giving to your views) with something more responsive.
If this was your non responsive button:
<Button
android:layout_width="200dp"
android:layout_height="400dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Just replace it with this:
<Button
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.3"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
For every phone, small or large this button will adjust according to the screen size and will take 30%
of the screen width and 50%
of the screen Width.
This is how you can make one screen responsive to all screen sizes and not create a lot of layouts for different screens.
How to set android layout to support all screen sizes?
Please go through the following links. These might help you:
Supporting Different Screen Sizes
Supporting Multiple Screens
Supporting Different Densities
Supporting Tablets and Handsets
AFAIK, the only way to support all screens is by doing that folder bifurcation. Every XML file goes up to a few kilo bytes. So, size shouldn't be too much of an issue as such.
How to support all the different resolutions of android products
You don't have to do that to support different densities. What you do is create different resources folders:
res/values-ldpi/dimens.xml
res/values-mdpi/dimens.xml
res/values-hdpi/dimens.xml
Then Android will decide which file to use. You can have something like:
<!-- in values-ldpi/dimens.xml -->
<dimen name="textSize">25dip</dimen>
and..
<!-- in values-mdpi/dimens.xml -->
<dimen name="textSize">20dip</dimen>
etc. And you shouldn't care about resolution... there are a lot of different resolutions sizes so it would be a hell to take decisions based on that.
Also, if you use dp
instead of pixels, you hardly ever will have to create different dimensions files for each density. Of course, sometimes you have to, but it depends on the app.
How to support different screen size in android
For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
The following code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
And also check out my SO answer.
Android screen in different resolutions
Yes, this can be confusing.
However, different devices have different amounts of 'DP's. The purpose of this is so that larger screens can hold more content. If you're using images, you can provide different sizes for different screen densities.
For more info, see this page: http://developer.android.com/guide/practices/screens_support.html
Related Topics
Difference Between Activity Context and Application Context
Android Imageview Zoom-In and Zoom-Out
How to Dynamically Add Elements to a Listview on Android
Getviewtypecount and Getitemviewtype Methods of Arrayadapter
How to Send an Object from One Android Activity to Another Using Intents
Listview Inside Scrollview Is Not Scrolling on Android
How to Change the Status Bar Color in Android
How to Make Links in a Textview Clickable
Firebase Onmessagereceived Not Called When App in Background
How to Use Drawerlayout to Display Over the Actionbar/Toolbar and Under the Status Bar
Android Studio Installation on Windows 7 Fails, No Jdk Found
How to Load Script from Assets Index.Android.Bundle on Windows
How to Set the Text Color of Textview in Code
Android: How to Get the Current Foreground Activity (From a Service)