1

I'm working on my game menu for android and I'm stuck to apply my layout for all devices screen size.

Do I have to size my layout in dp or with weight ?

I'am aware of doing many layout in layout-large, layout-small... and drawable-hdpi, drawable-ldpi ... but I'm still stuck.

How you will do it?

You can find a skeleton of what I want : http://imageshack.us/photo/my-images/14/menuskeleton.jpg/

Thank you !

Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
kakou
  • 179
  • 2
  • 13
  • check out [this link](http://stackoverflow.com/q/10812552) and then with proper setPadding or setMargin between the childs can enable you to get the desired layout you want – CRUSADER May 19 '13 at 09:28

2 Answers2

1

I advise you to use the weight to keep interoperability with other formats tablet.

My solution :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#AAAAAA"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    tools:ignore="DisableBaselineAlignment" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        tools:ignore="NestedWeights" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:background="#DDDDDD"
                android:gravity="center"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Shop"
                    tools:ignore="HardcodedText" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:background="#DDDDDD"
                android:gravity="center"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Ladder"
                    tools:ignore="HardcodedText" />

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="#DDDDDD"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Profil"
                tools:ignore="HardcodedText" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:background="#DDDDDD"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Recap_All"
            tools:ignore="HardcodedText" />

    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    tools:ignore="DisableBaselineAlignment" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:background="#DDDDDD"
        android:gravity="center"
        android:orientation="vertical"
        tools:ignore="NestedWeights" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            tools:ignore="HardcodedText" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:background="#DDDDDD"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="PLAY"
            tools:ignore="HardcodedText" />

    </LinearLayout>
</LinearLayout>

And result in picture :

enter image description here

I hope you have helped!

lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110
0

On this page of google developers, has a description of how to develop for different screen sizes.

And this page is the answer to your question about the size of your layout, it is between dp or weight.

See this also.

Wesley
  • 92
  • 1
  • 3
  • 9