Reputation: 137
I am writing an app that works very well on 720p screens. I want to make this app run on different screen sizes. I read this article: http://developer.android.com/guide/practices/screens_support.html
But I am confused. I made 3 folders for different layouts (layout-normal, layout-large, layout-xlarge) and placed a different XML file in each folder. But there are some screens that have layout-normal and my apps look good on some of them and look bad on others. For example, these sizes are normal layout: (4.7" WXGA, 4" WVGA, 3.7" WVGA, ...) But my app looks good on 4" and 3.7" and on other types looks very bad.
My activity-main.xml in the layout-normal folder is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backasli"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="100dp"
android:paddingTop="140dp"
android:stretchColumns="3" >
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="pray :"
android:textColor="#031a7b"
android:textSize="15sp" />
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/namaztxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#031a7b"
android:textSize="20sp" />
</TableRow>
<TableRow android:gravity="center" >
<Button
android:id="@+id/buttonchange"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/ubtn"
android:text="change"
android:textColor="#ffffff"
android:textSize="20sp" />
</TableRow>
</TableLayout>
</LinearLayout>
Upvotes: 0
Views: 1429
Reputation: 9574
Android provides a very good way to support multiple screen sizes. It's called weights. You should use LinearLayout
weights and check out your Graphical View to figure out how you want to resize.
Completely avoid:
Trust me, all the apps I have developed until now (12) have been done using weights with 1 layout file across all platforms. It works, and works like wonder.
Edit:
I also never use more than 5dp for padding and 10dp for margins. This way I keep the code clean and Android weights take care of my free space.
For more about weights, check out this question. It is really well explained to start with.
Edit Again:
Think about it. You are assuming dp to be the "same" in terms of physical mm (millimeters) for all phones. But it is not. In fact X and Y 1 dp may mean something different in "mm". dp is "not" consistent. Be careful when using code like 100dp and setting hardcoded widths and heights. And even worse, multiple layout files. You will get into a lot of code maintenance nightmares with those.
Upvotes: 2