0
votes

So I have 16 buttons with size of 80dp and they look good in 3.0" - 4.5" displays.
(source: gyazo.com)

When i get bigger screens like tablets it looks like this

(source: gyazo.com)

My custom button images are : ldpi 36x36,mdpi 48x48,hdpi 72x72,xhdpi 96x96 Here's my xml code :

<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:layout_gravity="center"
android:background="@drawable/background"
android:orientation="vertical" >

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id1"
        android:textColor="#FFF"
        android:textSize="15dp" 
        android:digits="1"
    />

    <Button
        android:id="@+id/button2"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id2"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button3"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id3"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button4"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id4"
        android:textColor="#FFF"
        android:textSize="15dp" />
</LinearLayout>

<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="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button5"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id5"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button6"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id6"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button7"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id7"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button8"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id8"
        android:textColor="#FFF"
        android:textSize="15dp" />
</LinearLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button9"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id9"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button10"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id10"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button11"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id11"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button12"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id12"
        android:textColor="#FFF"
        android:textSize="15dp" />
</LinearLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/Button01"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id13"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/Button02"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id14"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/Button03"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id15"
        android:textColor="#FFF"
        android:textSize="15dp" />

    <Button
        android:id="@+id/Button04"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/custom_button"
        android:onClick="id16"
        android:textColor="#FFF"
        android:textSize="15dp" />
</LinearLayout>

<RelativeLayout
    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:orientation="vertical" >

    <Button
        android:id="@+id/button13"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="47dp"
        android:background="@drawable/custom_button"
        android:onClick="numbers" />

</RelativeLayout>

1

1 Answers

2
votes

The size of the screen in dp is different for different screens. To make sure that every Button in a row occupies same amount of space, use android:layout_width="0dip" in combination with android:layout_weight="1". This will produce the same effect no matter of the screen size. Hope this helps.