Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

Basic XML Android Examples

The user interface in Android is defined using XML layout files. These files describe the visual structure and components using View and ViewGroup objects. The default main.xml file contains a LinearLayout as the root view group with a TextView child view. Additional views like an EditText text box can be added as children of the LinearLayout. Attributes like android:id, android:layout_width, android:layout_height, android:hint are used to further specify the views.

Uploaded by

donkarleon22
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Basic XML Android Examples

The user interface in Android is defined using XML layout files. These files describe the visual structure and components using View and ViewGroup objects. The default main.xml file contains a LinearLayout as the root view group with a TextView child view. Additional views like an EditText text box can be added as children of the LinearLayout. Attributes like android:id, android:layout_width, android:layout_height, android:hint are used to further specify the views.

Uploaded by

donkarleon22
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Android Development: Building the User Interface

Built using View and ViewGroup objects. View = buttons/text fields ViewGroup view containers, contain Views and ViewGroups

** UI is usually defined in XML document ** This is key for writing different layouts for different screen sizes

By default, main.xml has a LinearLayout root view group and a TextView child view
<?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="horizontal" > </LinearLayout>

To add a user-editable text box, add an <EditText> inside <LinearLayout>. EditText = subclass of view.
<EditText android:id="@+id/edit_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" />

android:id=@+id/edit_message A unique identifier for the view, which you can reference in your code @ is required, followed by the resource type id @+id/ The plus is needed when creating a resource ID for the first time references do not the + Then resource name other strings may use the same name as long as they are not the same type. android:layout_width and android:layout_height=wrap_content

wrap_content specifies that the view should only be as big as needed fill_parent would fill the screen

android:hint=@string/edit_message Default string to display when the text box is empty Refers to a string resource

android:layout_weight=1 Basically tells a button how much of the leftover space to consume every button starts with a default weight of 0.

android:onClick=sendMessage sendMessage is the name of a method in your activity that you want to call when the user selects the button! The method must Be public Have a void return value Have a View as the only parameter (which will be the View that was clicked) public void sendMessage(View view) { }

You might also like