user3578904
user3578904

Reputation: 65

Android grid on different screen sizes

I finished making a grid using the following:

<View
    android:id="@+id/test1"
    android:layout_width="fill_parent"
    android:layout_height="2dip"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/timerValue"
    android:layout_marginTop="60dp"
    android:background="#0000FF" />

<View
    android:id="@+id/test2"
    android:layout_width="fill_parent"
    android:layout_height="2dip"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/test1"
    android:layout_marginTop="96dp"
    android:background="#0000FF" />

<View
    android:id="@+id/test3"
    android:layout_width="fill_parent"
    android:layout_height="2dip"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/test2"
    android:layout_marginTop="116dp"
    android:background="#0000FF" />

<View
    android:id="@+id/test4"
    android:layout_width="fill_parent"
    android:layout_height="2dip"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/test3"
    android:layout_marginTop="130dp"
    android:background="#0000FF" />


<View
    android:id="@+id/test5"
    android:layout_width="2dp"
    android:layout_height="fill_parent"
    android:layout_marginLeft="90dp"
    android:background="#0000FF" />

<View
    android:id="@+id/test6"
    android:layout_width="2dp"
    android:layout_height="fill_parent"
    android:layout_marginLeft="180dp"
    android:background="#0000FF" />

<View
    android:id="@+id/test7"
    android:layout_width="2dp"
    android:layout_height="fill_parent"
    android:layout_marginLeft="270dp"
    android:background="#0000FF" />

The grid looks great on my phone, but I am wondering if it would look weird/wrong on phones of different sizes? Inside each grid is an item and I am not sure if the lines I am drawing would run in the middle of the items. Does the size of the phone make a difference on how my grid would be drawn..or any grid for that matter? If so is there a way to avoid this? The views are just drawing lines on the screen, but I am not sure if the lines and grid would come out uneven/weird looking on different phones.

Upvotes: 0

Views: 243

Answers (1)

Rosie
Rosie

Reputation: 94

I use eclipse, and in this IDE, the android SDK allows you to create different layouts for every type of screen, which according to android, are classified as following:
1. XXHDPI, XHDPI <- xtra large screens, I guess it'd be the 10" tablets
2. HDPI<- Large screes
3. MDPI<- medium screens
4. LDPI<- small screens

When you create a new layout, by default gives you the layout for a MDPI-HDPI, but if you want your app to be compatible with all screen sizes and not having design problems later, when you create a new layout, in the configuration option select as a qualifier the option size, and then select the screen size you want. With this option enable, when you debug your app with a real phone or a AVD, the app will adjust the layout automatically according to the dimensions of the phone.

It is kind of annoying to make a layout for every screen size, but it helps avoiding design problems.

Also, I suggest you to use GridView to make several views with only one layout.

Upvotes: 1

Related Questions