acivity_main.xml - batooldshilleh/TrainingTasks GitHub Wiki
Introduction:
This XML file defines the layout for an Android application's main activity.
What can we do within this file?
-
LinearLayout:
- This is the root layout container, which arranges its children linearly either vertically or horizontally.
- Attributes:
xmlns:android
: Defines the XML namespace for Android attributes.xmlns:app
: Defines the XML namespace for app-specific attributes.xmlns:tools
: Defines the XML namespace for design-time attributes.android:layout_width
: Specifies the width of the layout to match its parent.android:layout_height
: Specifies the height of the layout to match its parent.android:orientation
: Specifies the orientation of child views, in this case, vertical.android:layout_margin
: Specifies the margins around the layout.
-
EditText (et_a and et_b):
- Input fields where users can enter values for 'a' and 'b'.
- Attributes:
android:id
: Unique identifier for referencing in code.android:layout_width
: Specifies the width to match its parent.android:layout_height
: Specifies the height to wrap its content.android:hint
: Placeholder text shown when the field is empty.android:minHeight
: Specifies the minimum height of the EditText.tools:ignore
: Ignored tools-specific attributes.tools:layout_editor_absoluteX
: Specifies the X-coordinate for layout in the editor.android:autofillHints
: Autofill hints for the EditText.
-
LinearLayout (Nested):
- Another LinearLayout nested inside the root layout to hold buttons horizontally.
- Attributes:
android:layout_width
: Specifies the width to match its parent.android:layout_height
: Specifies the height to wrap its content.android:orientation
: Specifies the orientation of child views, in this case, horizontal.
-
Buttons (btn_add, btn_subtraction, btn_multiplication, btn_division):
- Buttons for performing addition, subtraction, multiplication, and division operations.
- Attributes:
android:layout_width
: Specifies the width to wrap its content.android:layout_height
: Specifies the height to wrap its content.android:text
: Text displayed on the button.android:layout_margin
: Specifies the margins around the button.android:id
: Unique identifier for referencing in code.
-
TextView (result_tv):
- Displays the result of the arithmetic operation.
- Attributes:
android:layout_width
: Specifies the width to match its parent.android:layout_height
: Specifies the height to wrap its content.android:text
: Text displayed in the TextView.android:textSize
: Size of the text.android:gravity
: Alignment of the text.android:id
: Unique identifier for referencing in code.android:layout_margin
: Specifies the margins around the TextView.