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.
Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements. Each layout file must contain exactly one root element, which must be a View or ViewGroup object.
Android provides three types of XML parsers which are DOM,SAX and XMLPullParser. Among all of them android recommend XMLPullParser because it is efficient and easy to use. So we are going to use XMLPullParser for parsing XML.
XML is now commonly found as part of UI development processes in spaces such as Android, JavaFX, UPF and Xmarin. It is also extensively used in Magneto, in addition to Microsoft based programs such as Word, Excel, and Powerpoint.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With