I am tried to creating a simple calculate app for android. I used a table layout and add 4 rows and 4 columns. In each column I add a button . My problem is the 4th column cuts out as shown in the image below,
Here is my code below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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: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="com.tashtoons.calculator.Calculator">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:weightSum="1"
android:layout_alignParentRight="false"
android:layout_alignParentEnd="false">
<TextView
android:layout_width="343dp"
android:layout_height="77dp"
android:id="#+id/answerScreen"
android:layout_gravity="center_horizontal" />
<TableLayout
android:layout_width="371dp"
android:shrinkColumns="1"
android:layout_height="match_parent"
android:baselineAligned="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="1"
android:id="#+id/button"
android:layout_column="0"
android:width="5px" />
<Button
android:text="2"
android:id="#+id/button2"
android:layout_column="1"
android:width="5px" />
<Button
android:text="3"
android:id="#+id/button3"
android:layout_column="2"
android:width="5px" />
<Button
android:text="+"
android:id="#+id/button4"
android:layout_column="3"
android:width="5px" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="4"
android:id="#+id/button5"
android:layout_column="0"
android:width="5px" />
<Button
android:text="4"
android:id="#+id/button6"
android:layout_column="1"
android:width="5px" />
<Button
android:text="5"
android:id="#+id/button7"
android:layout_column="2"
android:width="5px" />
<Button
android:text="-"
android:id="#+id/button8"
android:layout_column="3"
android:width="5px" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="6"
android:id="#+id/button9"
android:layout_column="0"
android:width="5px" />
<Button
android:text="7"
android:id="#+id/button10"
android:layout_column="1"
android:width="5px" />
<Button
android:text="8"
android:id="#+id/button11"
android:layout_column="2"
android:width="5px" />
<Button
android:text="X"
android:id="#+id/button12"
android:layout_column="3"
android:width="5px" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="9"
android:id="#+id/button13"
android:layout_column="0"
android:width="5px" />
<Button
android:text="0"
android:id="#+id/button14"
android:layout_column="1"
android:width="5px" />
<Button
android:text="%"
android:id="#+id/button15"
android:layout_column="2"
android:width="5px" />
<Button
android:text="/"
android:id="#+id/button16"
android:layout_column="3"
android:width="5px" />
</TableRow>
</TableLayout>
</LinearLayout>
</RelativeLayout>
How can I stop it from cutting out?
Instead of your code Use below code.
Whenever you have to give same width of all Button or TextView or etc.
There is property of LinearLayout is WeightSum . This can equal divided the part.
so change your xml code to below format.
xml code :
<RelativeLayout 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: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="com.example.softeng.xxy.ThirdActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:id="#+id/firstRow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/secondRow"
android:layout_below="#+id/firstRow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/thirdRow"
android:layout_below="#+id/secondRow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="X" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/forthRow"
android:layout_below="#+id/thirdRow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="%" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Output :
Try this it may be help to you
Use
android:layout_width="match_parent"
in your TableLayout
instead of
android:layout_width="371dp"
Where a view has weight = 1 you should set the layout_width to be 0dp to make them have an even amount or space on your screen
Related
I want to create an horizontal scroll view for my app
(I have six buttons needed to be distributed equally), everything
works fine when using smaller display (nexus 6 1440x 2560), but when using bigger display (pixel C 2560x1800) I got some space. I remarked
that LinearLayout width cover only the content even though I'm using
match_parent in android:layout_width
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.xieon_2.Home_dashboard">
<LinearLayout
android:id="#+id/main_vertical_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="30dp">
<HorizontalScrollView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageButton
android:id="#+id/bedroom_but"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:background="#drawable/round_shape"
android:src="#drawable/bedroom_icon" />
<ImageButton
android:id="#+id/kitchen_but"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="9dp"
android:background="#drawable/round_shape"
android:src="#drawable/kitchen_icon" />
<ImageButton
android:id="#+id/living_room_but"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="9dp"
android:background="#drawable/round_shape"
android:src="#drawable/living_room" />
<ImageButton
android:id="#+id/kids_room_but"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="9dp"
android:background="#drawable/round_shape"
android:src="#drawable/kids_room_icon" />
<ImageButton
android:id="#+id/bathroom_but"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="9dp"
android:background="#drawable/round_shape"
android:src="#drawable/bathroom_icon" />
<ImageButton
android:id="#+id/Guestroom_but"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="9dp"
android:background="#drawable/round_shape"
android:src="#drawable/guest_room" />
</LinearLayout>
</HorizontalScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="----------------------------------------------------------------"
android:textColor="#color/RoyalBlue"
android:textSize="20sp" />
<Button
android:id="#+id/control_but"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:text="Control" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<ImageView
android:id="#+id/temp_icon_2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:src="#drawable/temperature_icon" />
<TextView
android:id="#+id/temp_val"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/temp_icon_2"
android:text="26"
android:textColor="#color/RoyalBlue"
android:textSize="40sp" />
<TextView
android:id="#+id/degree_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/temp_val"
android:text="°"
android:textColor="#color/RoyalBlue"
android:textSize="40sp" />
<TextView
android:id="#+id/pcnt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:text="%"
android:textColor="#color/RoyalBlue"
android:textSize="40sp" />
<TextView
android:id="#+id/hum_val_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#+id/pcnt"
android:text="85"
android:textColor="#color/RoyalBlue"
android:textSize="40sp" />
<ImageView
android:id="#+id/humidity_icon_2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toStartOf="#+id/hum_val_2"
android:src="#drawable/humidity_icon" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<ImageView
android:id="#+id/noise_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/noise_unit"
android:src="#drawable/air_quality" />
<TextView
android:id="#+id/noise_val"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/noise_icon"
android:text="15"
android:textColor="#color/RoyalBlue"
android:textSize="40sp" />
<TextView
android:id="#+id/noise_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/noise_val"
android:text="PPM"
android:textColor="#color/RoyalBlue"
android:textSize="28sp" />
<TextView
android:id="#+id/security_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/noise_val"
android:layout_alignParentEnd="true"
android:layout_marginEnd="12dp"
android:text="ON"
android:textColor="#color/RoyalBlue"
android:textSize="35sp" />
<ImageView
android:id="#+id/security_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="#+id/noise_val"
android:layout_toStartOf="#+id/security_state"
android:src="#drawable/home_security"
android:layout_marginTop="10dp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
app with large display
app with small display
Firsty, I've created something like that:
BadLayout
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/button1"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button1"
android:textSize="18sp"/>
<Button
android:id="#+id/button2"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button2"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/button3"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button3"
android:textSize="18sp" />
<Button
android:id="#+id/button4"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button4"
android:textSize="18sp" />
</LinearLayout>
But this layout doesn't work properly. Buttons don't have fixed width. The wider the screen is, the wider buttons are. It doesn't look good for me, because I want buttons to be perfect squares (e.g. 120dp x 120dp). I also want them to be centered. It should looks like that: GoodLayout. How to do that?
you can try this code to manage your view according to image you added:
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="76dp"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_marginEnd="10dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button1"
android:textSize="18sp"/>
<Button
android:id="#+id/button2"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_marginStart="10dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button2"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="#+id/button3"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_marginEnd="10dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button3"
android:textSize="18sp" />
<Button
android:id="#+id/button4"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_marginStart="10dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button4"
android:textSize="18sp" />
</LinearLayout>
Try this code
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="2">
<Button
android:id="#+id/button1"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button1"
android:textSize="18sp"/>
<Button
android:id="#+id/button2"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button2"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="2">
<Button
android:id="#+id/button3"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button3"
android:textSize="18sp" />
<Button
android:id="#+id/button4"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="140dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:backgroundTint="#color/colorPrimary"
android:text="Button4"
android:textSize="18sp" />
</LinearLayout>
Try this answer it will surely work on any sreen size without changing size of button
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/button1"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="120dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button1"
android:textSize="18sp"
/>
<Button
android:id="#+id/button2"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginLeft="20dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button2"
android:textSize="18sp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:layout_marginTop="20dp"
android:orientation="horizontal"
>
<Button
android:id="#+id/button3"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="120dp"
android:backgroundTint="#color/colorPrimary"
android:text="Button3"
android:textSize="18sp" />
<Button
android:id="#+id/button4"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginLeft="20dp"
android:layout_gravity="center_vertical"
android:backgroundTint="#color/colorPrimary"
android:text="Button4"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
I'm currently working on an android application. I can't get buttons evenly spaced on a screen.
Below is my code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main_menu"
android:background="#354739"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.cssdapp.MainMenuActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
/>
<Button
android:text="Log Off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#6b5847"
android:id="#+id/logOff"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="Manage Farmers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#6b5847"
android:id="#+id/button4"
android:layout_above="#+id/button5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="My Account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#6b5847"
android:id="#+id/button5"
android:layout_marginBottom="47dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="Manage Farmers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#6b5847"
android:id="#+id/button3"
android:layout_above="#+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="21dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="Order History"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#6b5847"
android:id="#+id/button2"
android:layout_above="#+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="Make an Order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#6b5847"
android:id="#+id/makeOrder"
android:layout_above="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="36dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
I want the buttons evenly spaced down the screen below the image. At the minute the image is where I want to be however I can't get the buttons to where I want them to be. I'm trying to use the gui designer however they won't snap into place. I'm trying to figure out the code way to do it.
Any help appreciated.
In Order to divide the buttons on the whole screen evenly and to maintain synchronization on all devices you need to use a LinearLayout
as your parent View And and another LinearLayout as the parent for each button and apply to it the weight attribute to divide them evenly on the screen Cause you can't just apply the weight attribute on the button itself because the (height or width of it depends on if the layout orintation is horizontal or vertical will gets scaled to fill the whole space) here is a code snippet to demonstrate what am saying
`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main_menu"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/logOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log Off"
android:textAllCaps="false"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button4"
android:text="Manage Farmers"
android:textStyle="bold"
android:textAllCaps="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:text="My Account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button5"
android:textAllCaps="false"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:text="Order History"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:textAllCaps="false"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:text="Make an Order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/makeOrder"
android:textAllCaps="false"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>`
I have done some changes, Please check if it works for you
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#354739"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:src="#drawable/ic_android_black_24dp"/>
<Button
android:id="#+id/logOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iv"
android:layout_marginTop="23dp"
android:background="#6b5847"
android:text="Log Off"/>
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button5"
android:layout_marginTop="23dp"
android:background="#6b5847"
android:text="Manage Farmers"/>
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/logOff"
android:layout_marginTop="23dp"
android:background="#6b5847"
android:text="Manage Farmers"/>
<Button
android:id="#+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button4"
android:layout_marginTop="23dp"
android:background="#6b5847"
android:text="My Account"/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button5"
android:layout_marginTop="23dp"
android:background="#6b5847"
android:text="Order History"/>
<Button
android:id="#+id/makeOrder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button2"
android:layout_marginTop="23dp"
android:background="#6b5847"
android:text="Make an Order"/>
</RelativeLayout>
Edit, it's on top, now it's zoomed in
If it's possible, i would want it to fill the entire screen, width wise, with the image, completely on top, leaving no space between the top and the image. This is not working for me.
This is the main.xml code that I have, it could be completely wrong, please tell me if that's the case.
This is how it looks in the emulator, I want it to fill the entire top side from left to right, completely on the top.
Any help would be appreciated, i'm pretty new to this, so don't be scared to tell me i'm wrong :)
<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:gravity="center"
android:orientation="vertical"
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="com.example.rodekruis.MainActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/rkz_logo"
/>
</RelativeLayout>
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button9"
android:layout_alignLeft="#+id/button10"
android:layout_marginBottom="30dp"
android:layout_gravity="top"
android:clickable="true"
android:text="Nieuws" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignTop="#+id/button8"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Afspraak maken" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Bezoek tijden" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Contact" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Geef je mening!" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Route begeleiding" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignLeft="#+id/button5"
android:layout_below="#+id/button8"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Specia-listen" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="BWC" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Agenda" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Praktische
informatie" />
</LinearLayout>
</LinearLayout>
try this,
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:scaleType="centerCrop"
android:src="#drawable/rkz_logo"
/>
just remove your paddings. I hope it will help
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
Remove two line in layout root
android:gravity="center"
android:paddingTop="#dimen/activity_vertical_margin"
Try 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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
tools:context=".MainActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginBottom="30dp"
android:clickable="true"
android:text="Nieuws" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Afspraak maken" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Bezoek tijden" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Contact" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Geef je mening!" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text=" Route begeleiding" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignLeft="#+id/button5"
android:layout_below="#+id/button8"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Specia-listen" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="BWC" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Agenda" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Praktische informatie" />
</LinearLayout>
android:layout_alignParentTop="true" on the parent of the ImageView is ignored because its parent (the root view) is not a RelativeLayout. Try changing the root view to RelativeLayout, and remove its padding (at least the top one).
I am trying to make a calculator app. I have a outer linearlayout which is vertical orientation and then have nested linear layouts which have a horizontal orientation where my buttons will go. Only the last nested linear layout is not adjusting the width properly of the buttons as I want the '0' button to take half the width and the '.' and '=' button to take a quarter of the width. I gave the '=' button a layout weight of 0.5 and the '.' & '=' button a layout weight of 0.25 but it still won't work properly.
Here is a screenshot of the graphical layout:
XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
android:weightSum="1">
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_weight = "0.25"
android:layout_height="0dp"
android:textSize="40sp"
android:layout_gravity="right"
android:textColor="#FFFFFF"
android:id="#+id/tvDisplay"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.15"
android:weightSum="1">
<Button
android:id="#+id/bClear"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="C"
android:textSize="30sp" />
<Button
android:id="#+id/bChangeSign"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="+/-"
android:textSize="30sp" />
<Button
android:id="#+id/bPercent"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="%"
android:textSize="30sp" />
<Button
android:id="#+id/bDivide"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="/"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.15">
<Button
android:text="7"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b7"/>
<Button
android:text="8"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b8"/>
<Button
android:text="9"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b9"/>
<Button
android:id="#+id/bMultiply"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="x"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.15">
<Button
android:text="4"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b4"/>
<Button
android:text="5"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b5" />
<Button
android:text="6"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b6" />
<Button
android:text="-"
android:background="#FF9900"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/bSubtract"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.15">
<Button
android:text="1"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b1" />
<Button
android:text="2"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b2" />
<Button
android:text="3"
android:background="#FFFFFF"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/b3" />
<Button
android:text="+"
android:background="#FF9900"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:id="#+id/bPlus" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
<Button
android:id="#+id/b0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.5"
android:background="#FFFFFF"
android:text="0"
android:textSize="30sp" />
<Button
android:id="#+id/bDecimal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="."
android:textSize="30sp" />
<Button
android:id="#+id/bEquals"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="0.2dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="="
android:textSize="30sp" />
</LinearLayout>
The solution to this problem is remarkably simple.
Android is great, and the tools for developing it are great, but then you come across behaviors like this and you realize that it certainly isn't perfect yet.
Go ahead and change the android:layout_width in your 3 buttons at the bottom to
android:layout_width="0dp"
Now, this was the way this was explained to me. The layout_weight attribute tries to balance out the widths to be in the correct ratios, but it takes into account the widths of the buttons it is trying to balance. By setting the width to absolutely nothing (0dp), you're taking away any sort of widths that may have interfered with layout_weigth's attempts to balance the ratios. Basically, so that there are no other values that could throw off the shifting of the widths.
I hope that helps. Good luck :)
test well
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:id="#+id/tvDisplay"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_weight="0.25"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="40sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/bClear"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="C"
android:textSize="30sp" />
<Button
android:id="#+id/bChangeSign"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="+/-"
android:textSize="30sp" />
<Button
android:id="#+id/bPercent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="%"
android:textSize="30sp" />
<Button
android:id="#+id/bDivide"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="/"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/b7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="7"
android:textSize="30sp" />
<Button
android:id="#+id/b8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="8"
android:textSize="30sp" />
<Button
android:id="#+id/b9"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="9"
android:textSize="30sp" />
<Button
android:id="#+id/bMultiply"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="x"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/b4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="4"
android:textSize="30sp" />
<Button
android:id="#+id/b5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="5"
android:textSize="30sp" />
<Button
android:id="#+id/b6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="6"
android:textSize="30sp" />
<Button
android:id="#+id/bSubtract"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="-"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/b1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="1"
android:textSize="30sp" />
<Button
android:id="#+id/b2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="2"
android:textSize="30sp" />
<Button
android:id="#+id/b3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="3"
android:textSize="30sp" />
<Button
android:id="#+id/bPlus"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="+"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/b0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.5"
android:background="#FFFFFF"
android:text="0"
android:textSize="30sp" />
<Button
android:id="#+id/bDecimal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FFFFFF"
android:text="."
android:textSize="30sp" />
<Button
android:id="#+id/bEquals"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0.1dp"
android:layout_weight="0.25"
android:background="#FF9900"
android:text="="
android:textSize="30sp" />
</LinearLayout>