0

How can I optimize my app to support multiple screen sizes? I am working on a project where most of graphics are XML drawables with no defined size. I have tried with dimens in values folders(ldpi,mpdi,etcetc) but that didn't really do the work. I was stuck with some items going out of screen so I tried with creating different layouts for each screen size, but same thing happens, app looks nice on 4.3...5"" devices but when I launch 3.7 emulator, app looks bad and some items are out of screen/covered by other items. I am using relative layout, I don't see the need for the code but if needed I will post. My question is: What is the best way to optimize app to support multiple screen sizes?

Slim C.
  • 1,119
  • 4
  • 25
  • 49

3 Answers3

1

I think your starting point should be to look through this page by Google: https://developer.android.com/guide/practices/screens_support.html

But also, here are some pointers:

  • Make liberal use of "wrap_content" and "match_parent" height and width layout properties. Avoid, setting explicit sizes where possible
  • When you do need to set explicit sizes, consider using the dimen.xml for different screens or consider setting the values pro grammatically
  • Make sure to have different res images in your drawables, don't forget about the drawables-nodpi folder
soundsofpolaris
  • 596
  • 3
  • 12
0

The best way I've found is to be extremely thoughtful when defining your layouts in XML. In most situations you will find that you can define your layouts so that they will scale appropriately between devices until you get to the really high end.

Take this layout for example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLinView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/KeywordItemViewMain"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="@dimen/defViewMargin"
    android:layout_marginRight="@dimen/defViewMargin"
    android:layout_marginTop="@dimen/defViewMarginTopBottom"
    android:layout_marginBottom="@dimen/defViewMarginTopBottom"
    android:background="@drawable/rounded_corners_background"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="@dimen/defViewPadding" >

    <TextView
        android:id="@+id/rowKeywordTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="5dp"
        android:text="@string/keywordrow_name"
        android:textSize="15sp"
        android:textStyle="bold" />

</LinearLayout>

<LinearLayout
    android:id="@+id/icons"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/KeywordItemViewMain"
    android:layout_centerVertical="true" >

    <ImageView
        android:id="@+id/acknowledgedIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/handled"
        android:padding="5dp"
        android:src="@drawable/acknowledge_item_icon" />
</LinearLayout>

Fill Parent & Wrap Content will be your best friends.

I only ever use the folders small, normal, large and X-large when I really need to specify differently designed layouts between phones or with the really high/low end screen sizes where necessary as I find it annoying to make 4/5 edits every time I want to minor modifications to the layout.

jwv
  • 475
  • 4
  • 21
-1

You should create 4 folders for every kind of screen sizes (small, normal, large and X-large). Right click on res folder in your editor and choose New-->AndroidResourceDirectory choose size from Available qualifier and create every kind of size folders. good luck

  • This method has been mostly deprecated because it had no correlation with screen sizes and new densities. A 2014 phone would be x-large, same as a 2011 tablet. – MLProgrammer-CiM Oct 29 '14 at 18:21