Reputation: 179
Should I create different layout folders to store my xml layout files. To support my application over different screen sizes?
I developed an application and when adding drawables it automatically creates different sizes like xdpi ldpi and more but layouts xml file are not auto created to support different screen sizes. should I do it? and also i will edit manifest file to support different sizes by using support-screen tag. and is this all?? And will it also support my landscape or portrait mode. Please confirm me. I am new to stack and android development.
Edit: I believe different layout files in different folders.. will just be a copy of each other with only folder name change ad shown in code
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
This is my layout xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context="com.example.root.meeransunday.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="200dp"
android:layout_height="90dp"
android:text="Send Mobile"
android:drawableLeft="@mipmap/sms"
android:layout_alignParentBottom="true"
android:layout_marginRight="-1dp"
android:layout_marginLeft="-3dp"
android:layout_marginBottom="-4dp"
android:onClick="message"/>
<Button
android:id="@+id/button2"
android:layout_width="200dp"
android:layout_height="90dp"
android:text="QR Code"
android:drawableLeft="@mipmap/qr"
android:layout_marginLeft="190dp"
android:layout_marginRight="-20dp"
android:layout_marginBottom="-4dp"
android:layout_alignParentBottom="true"
android:onClick="scan"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:text=" My Account Balance"
android:textColor="#0D47A1"
/>
<TextView
android:text="PKR 1527.87"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:drawableLeft="@mipmap/money"
android:textSize="35sp"
android:id="@+id/textView2"
/>
</RelativeLayout>
Manifest file:
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
android:resizeable="true"/>
but it does not work on 4 inch screen.
Upvotes: 5
Views: 3111
Reputation: 1265
No need to design all the Layouts,If you are making app for Phone as well as Tablets then you can design 2 Layouts. Otherwise design only these 1. Portrait 2. Landscape
Upvotes: 1
Reputation: 2583
Actually creating different xml layouts for different android devices it's depends on requirement. It's always good to have only one xml layout for all type of devices to avoid redundant code, But we can go for creating xml's for all type devices, android has that feature.
Upvotes: 2
Reputation: 1536
If the layout is the same, there's no need to create multiple layout files, you should use different dimens files to adjust the size of your elements.
If you want your application to look different on a hdpi device than it looks on a xxxhdpi or if you have a mobile and a tablet version of the screen, then you should use multiple layout files.
Upvotes: 5
Reputation:
This should be helpful : https://developer.android.com/guide/practices/screens_support.html
Anyway I think that you should use max 2 layouts xmls (1 for horizontal view, 1 for vertical view) for activity.
Upvotes: 4