user3519421
user3519421

Reputation: 23

Fix Layout of Android-Application for diffrent devices

My question is to How can i fix my layout of Android-Application.Because when i run my application in one device its looks good but on another emulator it looks so small.I want to look it same on all devices

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical" 
     android:background="@drawable/axelorbackground">

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Axelor CRM"
            android:textColor="#CCFF99"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView1"
            android:src="@drawable/logoaxelor" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center" >

        <Button
            android:id="@+id/btnsynchronize"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
               android:textColor="#CCFF99"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/sync"
            android:text="Synchronization" />
    </RelativeLayout>

    <ScrollView
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/footer"
        android:layout_below="@id/header"
        android:layout_marginTop="50dp" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TableLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TableRow android:padding="10dp" >

                    <TabWidget android:padding="5dp" >

                        <Button
                            android:id="@+id/btntickets"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:background="@drawable/homebuttons"
                            android:drawableTop="@drawable/ticket"
                            android:text="Tickets"
                            android:textColor="#FFFFFF"
                            android:textSize="12dp" />
                    </TabWidget>

                    <TabWidget android:padding="5dp" >

                        <Button
                            android:id="@+id/btnOpportunity"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:background="@drawable/homebuttons"
                            android:drawableTop="@drawable/opportunity"
                            android:text="Opportunity"
                             android:textColor="#FFFFFF"
                            android:textSize="12dp" />
                    </TabWidget>
                </TableRow>

                <TableRow android:padding="10dp" >

                    <TabWidget android:padding="5dp" >

                        <Button
                            android:id="@+id/btnMeetings"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:background="@drawable/homebuttons"
                            android:drawableTop="@drawable/meetings"
                            android:text="Meetings"
                           android:textColor="#FFFFFF"
                            android:textSize="12dp" />
                    </TabWidget>

                    <TabWidget android:padding="5dp" >

                        <Button
                            android:id="@+id/btnleads"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:background="@drawable/homebuttons"
                            android:drawableTop="@drawable/lead"
                            android:text="Leads"
                         android:textColor="#FFFFFF"
                            android:textSize="12dp" />
                    </TabWidget>
                </TableRow>

                <TableRow android:padding="10dp" >

                    <TabWidget android:padding="5dp" >

                        <Button
                            android:id="@+id/btnTask"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:background="@drawable/homebuttons"
                            android:drawableTop="@drawable/task"
                            android:text="Task"
                             android:textColor="#FFFFFF"
                            android:textSize="12dp" />
                    </TabWidget>

                    <TabWidget android:padding="5dp" >

                        <Button
                            android:id="@+id/btnCalls"
                            android:layout_width="110dp"
                            android:layout_height="110dp"
                            android:background="@drawable/homebuttons"
                            android:drawableTop="@drawable/calls"
                            android:text="Calls"
                         android:textColor="#FFFFFF"
                            android:textSize="12dp" />
                    </TabWidget>
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

Upvotes: 1

Views: 242

Answers (4)

Nouman Bhatti
Nouman Bhatti

Reputation: 1837

There are two ways of supporting multiple screens in Android:

  1. Make seperate layouts for normal, large (7inch), and xlarge (10inch) screens. http://developer.android.com/guide/practices/screens_support.html

  2. Use dimensions to stretch the app without creating new layouts, as so:
    res/values/dimensions.xml
    res/values-sw600dp/dimensions.xml → 7+ inches
    res/values-sw720dp/dimensions.xml → 10+ inches

The first method is simple, but not very efficient because it requires creating and altering the layouts for each screen size, so I would recommend the second method.

Upvotes: 0

Prashant Mishra
Prashant Mishra

Reputation: 627

you can achieve it dynamically..

step 1- get the width and height using

Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight();

or

DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);

height = metrics.heightPixels; width = metrics.widthPixels;

then after it divide the width and height according to the your view need and set it.

like:

text view.setWidth(height/2); text view.sethight(width/2);

so you have to do it dynamically in activity class.

hope it works for you.. :)

Upvotes: 1

user3068976
user3068976

Reputation:

All devices have its own screen ratio. so if you will make static layout for one device then in other device it will not fit. So make it dynamic using its width and height as "wrap-content","fill-parent" or "match-parent".

Upvotes: 1

Pihu
Pihu

Reputation: 1039

Your question is not clear, as far as i got to know, try to avoid static width or height of the layout in your xml code instead use, fill parent or wrap content.

Upvotes: 1

Related Questions