Link to home
Start Free TrialLog in
Avatar of Modifier1000
Modifier1000Flag for United States of America

asked on

Need help arranging icons on Main Activity

Hello Experts,

My main activity has 4 icons and I'd like to have them organized.  Currently, they are not per my screenshots.  Any help to accomplish the layout on the right side in the attached file would be very much appreciated.

Here is my code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:baselineAligned="_baseline"
    android:focusable="true"
    android:orientation="horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Main" >

    <ImageButton
        android:id="@+id/news"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="28dp"
        android:layout_marginTop="56dp"
        android:background="@drawable/news"
        android:contentDescription="@string/Contact"
        android:src="@drawable/news" />

    <ImageButton
        android:id="@+id/contact"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="18dp"
        android:background="@drawable/contact"
        android:contentDescription="@string/News"
        android:src="@drawable/contact" />

    <ImageButton
        android:id="@+id/locations"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/locations"
        android:contentDescription="@string/Parks"
        android:src="@drawable/locations" />

    <ImageButton
        android:id="@+id/schedules"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/schedules"
        android:contentDescription="@string/schedules" />

</LinearLayout>

Open in new window

Arranging-Icons-on-Main.png
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

I do not know a lot about layouts, but what I think you need is the onMeasure() method

http://developer.android.com/guide/topics/ui/custom-components.html

Googleling square layout produces a lot of answers, a lot of whom seem to think gridview is the way to go

http://stackoverflow.com/questions/6557516/making-grid-view-items-square

where as others go with table

http://stackoverflow.com/questions/12555106/android-layout-with-4-squares-and-a-button-inside-each-square
ASKER CERTIFIED SOLUTION
Avatar of Molnár István
Molnár István
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Modifier1000

ASKER

Yep, I changed to Relative and got what I wanted...thank you.