How to fit "Buttons" into frame using "table row"? - android

I'm making a calculator but inside frame, it's not fitting.
I'm using "Table Layout" inside it.
but it's showing this.
While I wanted to make like this.
please help, how to fix my button proper inside frame? thanks.
Here is my source code for "button".
<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="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#cccccc"
android:padding="15dp"/>
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TableRow>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7"/>
<Button
android:id="#+id/btn8"
android:text="8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="9"
android:layout_weight="1"/>
<Button
android:id="#+id/btnDivide"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="÷"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="4"
android:layout_weight="1"/>
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5"
android:weight="1"/>
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="6"
android:weight="1"/>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="7"
android:weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>

In the last 3 buttons' xml, you write android:weight="1" which will be android:layout_weight="1"
<TableRow>
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="4"
android:layout_weight="1"/>
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5"
android:layout_weight="1"/>
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="6"
android:layout_weight="1"/>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="7"
android:layout_weight="1"/>
</TableRow>

Related

How to cut the screen?

I made my own simple calculator but I want to cut it, Can anyone help how do it?
Following is my pic where I want to cut this.
I used:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
But it's not working.pls help!
Here is my source code:
<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="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#cccccc"
android:gravity="right"
android:padding="15dp"/>
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TableRow>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7"/>
<Button
android:id="#+id/btn8"
android:text="8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="9"
android:layout_weight="1"/>
<Button
android:id="#+id/btndiv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="÷"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="4"
android:layout_weight="1"/>
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5"
android:layout_weight="1"/>
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="6"
android:layout_weight="1"/>
<Button
android:id="#+id/btnx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="1"
android:layout_weight="1"/>
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1"/>
<Button
android:id="#+id/btn3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="3"
android:layout_weight="1"/>
<Button
android:id="#+id/btnsub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="-"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0"
android:layout_weight="1"/>
<Button
android:id="#+id/btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="C"
android:layout_weight="1"/>
<Button
android:id="#+id/btnequal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="="
android:layout_weight="1"/>
<Button
android:id="#+id/btnadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="+"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
your main Linear Layout change like this change this line android:layout_height="wrap_content"
<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:background="#ff00ff00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#cccccc"
android:gravity="right"
android:padding="15dp" />
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TableRow>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" />
<Button
android:id="#+id/btn8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8" />
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9" />
<Button
android:id="#+id/btndiv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="÷" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6" />
<Button
android:id="#+id/btnx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="x" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<Button
android:id="#+id/btn3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<Button
android:id="#+id/btnsub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<Button
android:id="#+id/btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C" />
<Button
android:id="#+id/btnequal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="=" />
<Button
android:id="#+id/btnadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
</TableRow>
</TableLayout>
</LinearLayout>
android:theme="#android:style/Theme.DeviceDefault.Dialog.NoActionBar"
by adding this line to your manifest
<activity
android:name=".DemoActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.Dialog.NoActionBar" >
Or Try this in your xml:-
<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="vertical"
android:padding="30dp" >
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#cccccc"
android:gravity="right"
android:padding="15dp" />
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" />
<Button
android:id="#+id/btn8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8" />
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9" />
<Button
android:id="#+id/btndiv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="÷" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6" />
<Button
android:id="#+id/btnx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="x" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<Button
android:id="#+id/btn3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<Button
android:id="#+id/btnsub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/btn0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<Button
android:id="#+id/btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C" />
<Button
android:id="#+id/btnequal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="=" />
<Button
android:id="#+id/btnadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
</TableRow>
</TableLayout>

Creating a table with buttons in Android, compatible with both tablet and smartphone

Hi Guys I'd like to create a menu page with buttons like in the picture
http://i.stack.imgur.com/q1Bx7.jpg
I already tried with linear layouts and table layouts, but it wasn't working. Can anyone help me? The buttons should be relative in size so the page is shown correctly on tablets and on smartphones.
Edit: This is my code
<TableLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
</TableLayout>
this is how i did it in my app.. you can reference it. it does what you showed in the image.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:text="1"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:text="2"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="10sp"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="#+id/btn3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:text="3"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="#+id/btn4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:text="4"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>

Why layout is different in graphical layout and AVD , where both are working on android 2.2 API 8

I am making one layout but when i see that layout in graphical layout and in AVD manager, AVD manager displays somewhat different layout than graphical layout. Please help me to fix this problem.
look at below..
enter link description here
Unfortunatley I cannot comment on your post.. but could you please upload your .xml file? Maybe you built your layout on a "screen" with a resolution different from the one of AVD VM or you are using a relative layout. Just post the .xml
Try changing your xml layout like this :
<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="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#54616d"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dial Number"
android:textColor="#f7edb3"
android:textSize="20dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="0dp"
/>
<View
android:id="#+id/separator"
android:background="#f7edb3"
android:layout_width = "fill_parent"
android:layout_height="1dip"
android:layout_centerVertical ="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:background="#fff"
android:layout_marginTop="15dp"
/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="1"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="3"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="2"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="4"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="6"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="5"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="7"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="8"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="9"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="*"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="0"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="#"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<Button
android:id="#+id/dial"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#c79c00"
android:text="Dial" />
</TableRow>
</TableLayout>
</LinearLayout>

Weird unexplainable "switch" between ids in Android XML

I have a really weird problem.
This is my full XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="#+id/disp_nums" android:textSize="64sp"
android:layout_width="200dp" android:layout_height="100dp"
android:layout_gravity="center" android:gravity="center" android:text="1111" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<EditText android:id="#+id/ent_nums" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:hint="Entered numbers" />
<Button android:id="#+id/enter" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="0.37"
android:text="Enter" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_marginTop="15dp"
android:weightSum="90">
<Button android:id="#+id/button7" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="7" android:layout_weight="30"/>
<Button android:id="#+id/button8" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="8" android:layout_weight="30"/>
<Button android:id="#+id/button9" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="9" android:layout_weight="30"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:weightSum="90">
<Button android:id="#+id/button4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="4" android:layout_weight="30"/>
<Button android:id="#+id/button5" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="5" android:layout_weight="30"/>
<Button android:id="#+id/button6" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="6" android:layout_weight="30"/>
</LinearLayout>
<LinearLayout android:weightSum="90"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="#+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="1" android:layout_weight="30"/>
<Button android:id="#+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="2" android:layout_weight="30"/>
<Button android:id="#+id/button3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40sp"
android:text="3" android:layout_weight="30"/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:weightSum="90">
<Button android:id="#+id/button0" android:layout_width="90dp"
android:layout_height="wrap_content" android:layout_weight="60"
android:text="0" android:textSize="30sp" />
<Button android:id="#+id/delete" android:layout_width="40dp"
android:layout_height="fill_parent" android:layout_weight="30"
android:text="Del" android:textSize="24sp"/>
</LinearLayout>
</LinearLayout>
My "0" and "Del" buttons seem to be opposite in their actions. Meaning when I click "0" it actually deletes everything and when I click "Del" it types the "0" character. HOWEVER, when I simply switch (see second code) between their physical positions then they both do their right part.
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:weightSum="90">
<Button android:id="#+id/delete" android:layout_width="40dp"
android:layout_height="fill_parent" android:layout_weight="30"
android:text="Del" android:textSize="24sp"/>
<Button android:id="#+id/button0" android:layout_width="90dp"
android:layout_height="wrap_content" android:layout_weight="60"
android:text="0" android:textSize="30sp" />
</LinearLayout>
What could possibly be causing this?

How to manage Layout In android

I had just started working on android. Actually I had created a calculator application.
The problem I have faced is to manage the layout. I have two rows of buttons. In each row are 4 buttons. When I run the application the space between the first row and the second row is quite large. So can anyone tell me how can I decrease the space between these two rows?
The code I have written:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Calculator Application"/>
<EditText
android:id="#+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/label"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="1" />
<Button
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="2" />
<Button
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="3" />
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="+" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="4" />
<Button
android:id="#+id/five"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="5" />
<Button
android:id="#+id/six"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="6" />
<Button
android:id="#+id/minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="-" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/seven"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="7" />
<Button
android:id="#+id/eight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="8" />
<Button
android:id="#+id/nine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="9" />
<Button
android:id="#+id/multiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="*" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="0" />
<Button
android:id="#+id/clr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="c" />
<Button
android:id="#+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="=" />
<Button
android:id="#+id/divide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="/" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Regards
Anshuman
Replace all of the
android:layout_height="fill_parent" calls to
android:layout_height="wrap_content"
(apart from the parent layout, which should be fill_parent)
I have verified that this works.
EDIT: To make the buttons fill the screen horizontally, (and all be equally sized), add this to each button:
android:layout_width="0dp"
android:layout_weight="1"
the better way is u can use grid layout.try this links
http://www.edumobile.org/android/android-beginner-tutorials/draw-menu-in-grid-view/
http://www.firstdroid.com/2011/02/06/android-tutorial-gridview-with-icon-and-text/
As CaspNZ suggested use android:layout_height="wrap_content" also using top padding may help.

Categories

Resources