Hi , Now I am moving towards new Program that is Android Studio Calculator , a very basic calculator which will look as below :
Android Studio |
Step 1 : Create a new project named as Android Studio Calculator Example
Android Studio |
Step 2 : activity_main.xml
Now , add one textview to show output .
In two textview with text as First no. and other Second no.
Two editview to enter no.s
Four buttons as ADD,SUB,MUL and DIV
Below is the code for activity_main.xml
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:weightSum="1"
android:background="#fff9fdff">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text=""
android:id="@+id/textView1"
android:visibility="visible"
android:autoText="true"
android:background="#fffffad9" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="@android:dimen/app_icon_size"
android:layout_weight="0.19">
<TextView
android:layout_width="10dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="First No."
android:id="@+id/textView2"
android:layout_weight="0.09" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:layout_weight="0.09" />
<TextView
android:layout_width="10pt"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Second No."
android:id="@+id/textView3"
android:layout_weight="0.09" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_weight="0.09" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ADD"
android:id="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SUB"
android:id="@+id/button2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MUL"
android:id="@+id/button3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DIV"
android:id="@+id/button4" />
</LinearLayout>
</RelativeLayout>
Post a Comment