2

I met some trouble when I designed the layout of the calculator. As the pic shows, I want it to look like the pic1 but no matter how I change the code, it still looks like pic2. Here is the pics and my code! Hope someone can help me solve this problem.

(pic1)
enter image description here

(pic2)
enter image description here

Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/question_text_view"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:padding="24dp" />

    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/C_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"

            android:text = "C" />

        <Button
            android:id = "@+id/del_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "del" />

        <Button
            android:id="@+id/divide_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="/"/>

        <Button
            android:id="@+id/mul_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"      
            android:text="X"/>
    </LinearLayout>    

    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/seven"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "7" />

        <Button
            android:id = "@+id/eight_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "8" />

        <Button
            android:id="@+id/nine_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="9"/>

        <Button
            android:id="@+id/minus_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"      
            android:text="-"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/four"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "4" />

        <Button
            android:id = "@+id/five_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "5" />

        <Button
            android:id="@+id/six_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="6"/>

        <Button
            android:id="@+id/plus_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"      
            android:text="+"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/one"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "1" />

        <Button
            android:id = "@+id/two_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "2" />

        <Button
            android:id="@+id/three_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="3"/>

        <Button
            android:id="@+id/equal_button"
            android:layout_rowSpan="2"
            android:layout_gravity="fill"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="="/>
    </LinearLayout>
</LinearLayout>
Ken Choi
  • 33
  • 3
  • **1** - There's some padding in your styles or themes. Remove it. **2** - You don't need to nest layouts (it's bad for performances). A GridLayout is better suited for this UI. – Phantômaxx Oct 19 '15 at 08:53
  • @Ken Choi what you are doing is adding buttons and what there in PIC-1 is not button as pointed by Frank it is a grid view that's why you are not getting that look – dex Oct 19 '15 at 08:56
  • @dex okay, thanks! i know what's my problem! – Ken Choi Oct 20 '15 at 12:14

2 Answers2

2

Just replace the background of your Button, Android's default Button has transparent pixels in background image

Tang Ke
  • 1,508
  • 12
  • 12
2

Use grid layout for this

visit http://sampleprogramz.com/android/gridlayout.php

this would help you - How to make a GridLayout fit screen size

Community
  • 1
  • 1
Karthik Kumar
  • 1,375
  • 1
  • 12
  • 29