Mobile Application Development Assignment Submittion(1)
Mobile Application Development Assignment Submittion(1)
In Android, a View (public class Views) is the basic building block for
creating UI components. Think of it as a small rectangle on the screen
that can display content or respond to user interactions. Each View is a
fundamental element for creating various types of interactive and display
components in an app.
Basic Views include:
TextView
TextView is one of the most fundamental View types. It’s used to display
text to the user. You can customize the appearance of the text by changing
its color, size, font, and alignment.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="24sp"
android:textColor="#0000FF"
android:textStyle="bold"
android:gravity="center"
/>
Button
A Button is a UI component in Android used to trigger actions or events
when clicked. It's a common element in most Android apps.
Key Attributes of Button:
Here are some of the most important attributes you can use to customize a
Button:
Basic Attributes:
android:text: Sets the text displayed on the button.
android:textSize: Sets the font size of the text.
android:textColor: Sets the text color.
android:textStyle: Sets the font style (bold, italic, bold italic).
android:background: Sets the background color or drawable.
Layout Attributes:
State-Specific Attributes:
ImageView
ImageView is pretty self-explanatory: it’s used for displaying images. You
can manipulate images in ImageView, such as resizing them or changing
their aspect ratio.
Key Attributes of ImageView:
Here are some of the most important attributes you can use to customize an
ImageView:
Basic Attributes:
android:src: Sets the image resource to be displayed.
android:scaleType: Controls how the image is scaled within the
ImageView's bounds.
android:adjustViewBounds: Adjusts the view's bounds to preserve the
aspect ratio of the image.
android:maxWidth: Sets the maximum width of the image.
android:maxHeight: Sets the maximum height of the image.
Layout Attributes:
EditText
EditText is an interactive TextView that allows users to input and edit
text. It’s commonly used in forms, search bars, and messaging apps. You
can use various input types like text, number, and password, and set
various properties to control the text, like limiting the number of
characters or allowing only numbers.
Key Attributes:
Basic Attributes:
android:text: Sets the initial text displayed in the EditText.
android:hint: Sets a hint text that disappears when the user starts typing.
android:textSize: Sets the font size of the text.
android:textColor: Sets the text color.
android:inputType: Specifies the keyboard type (e.g., text, number,
phone, email).
android:maxLines: Sets the maximum number of lines allowed.
android:imeOptions: Sets the Input Method Editor (IME) options (e.g.,
actionDone, actionNext).
Example Usage:
XML
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:inputType="textCapWords"
/>
CheckBox
A CheckBox is employed for multiple options that can be either checked or
unchecked. They are often used in settings and forms and operate
independently from one another.
Key Attributes:
Basic Attributes:
android:text: Sets the text displayed next to the checkbox.
android:checked: Sets the initial checked state (true or false).
android:button: Sets the appearance of the checkbox button.
Example Usage:
XML
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to the terms and conditions"
/>
RadioButton
A RadioButton is used for making a single selection from a group of options.
When one RadioButton in a group is selected, the others are automatically
deselected. This makes them perfect for choices like selecting a payment
method or choosing a shipping option.
Key Attributes:
Basic Attributes:
android:text: Sets the text displayed next to the radio button.
android:checked: Sets the initial checked state (true or false).
android:button: Sets the appearance of the radio button.
Example Usage:
XML
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" /></RadioGroup>
Switch
A Switch is a two-state toggle that can select between two options, often
used in settings for turning a feature on or off. It provides a quick and easy
way for users to control a setting.
Key Attributes:
Basic Attributes:
android:textOn: Sets the text to display when the switch is on.
android:textOff: Sets the text to display when the switch is off.
android:checked: Sets the initial checked state (true or false).
android:thumb: Sets the appearance of the thumb.
android:track: Sets the appearance of the track.
Example Usage:
XML
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off" />
ProgressBar
A ProgressBar is used to display the progress of an operation, providing
visual feedback to the user. They can be styled as a spinning wheel or a
horizontal bar filling up.
Key Attributes:
Basic Attributes:
android:indeterminate: Sets whether the progress bar is indeterminate
(displays an animation) or determinate (shows a specific progress).
android:max: Sets the maximum value of the progress bar.
android:progress: Sets the current progress value.
android:style: Sets the style of the progress bar (horizontal, vertical,
circular).
Example Usage:
XML
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
/>
SeekBar
A SeekBar is a type of ProgressBar that adds a thumb to the progress line
which a user can drag to set a value within a predefined range. It’s often used
for settings like adjusting volume or screen brightness.
Key Attributes:
Basic Attributes:
android:max: Sets the maximum value of the seek bar.
android:progress: Sets the current progress value.
android:thumb: Sets the appearance of the thumb.
android:track: Sets the appearance of the track.
Example Usage:
XML
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
/>
Conclusion
Designing an effective activity layout in Android involves utilizing these
views' attributes strategically to create a user-friendly interface.
Understanding how to manipulate these attributes allows developers to
customize their applications to better meet user needs and enhance the
overall user experience.