i’ve developed an android app, but sometimes users call me and tell me that layout is incorrect to their device. The cause is that android runs on devices with different screen size and density. I try to cover all the type, but when i correct something, other things become incorrect. Damn! Is there a way to create just one layout with one folder of drawable and use something to scale layout in function of different screen size? Thank you!!
This is an example of my main xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@drawable/sfondo">
<LinearLayout android:id="@+id/linearLayout2"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout android:id="@+id/linearLayout1"
android:layout_height="fill_parent" android:weightSum="1"
android:layout_width="fill_parent" android:orientation="horizontal">
<ImageView android:layout_height="wrap_content" android:id="@+id/imageView1"
android:src="@drawable/trovachiavi_contatti" android:layout_width="wrap_content"
android:layout_marginTop="15dp" android:layout_marginLeft="20dp"></ImageView>
<ImageButton android:id="@+id/infoButton"
android:background="@null" android:layout_height="47dp"
android:layout_marginLeft="5dip" android:layout_weight="0.25"
android:layout_marginTop="15dip" android:src="@drawable/info_mini"
android:layout_width="47dp">
</ImageButton>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/layoutGif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<trova.chiavi.sd.GIFView
android:layout_gravity="center"
android:layout_height="220dp" android:layout_width="210dp" android:id="@+id/GIFSingle"
android:layout_marginLeft="40dp"></trova.chiavi.sd.GIFView>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/testoBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:maxLines="2"/>
<ImageView
android:id="@+id/Banner"
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_gravity="center"
android:src="@drawable/box_codice"
android:layout_marginTop="5dp"
/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="1dp">
<ImageButton
android:id="@+id/avvia_cerca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/chiave"
android:layout_gravity="center"/>
<TextView
android:id="@+id/testoRicercaSingle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
using layoutSum and layoutWeight you can resize all content with a percent. I work with linearlayout and this parameters and i do only one layout for every screen size !! 🙂