Create a simple Android application using TableLayout (table layout manager) and TableRow (table row layout manager). A scoring component.
1. Open Android studio to create an Android application, name the Application name TableLayout, and name the Company Domain Example.com 2.
Select API 18 for Minimum SDK: Android 4.3
3. Select Empty Activity
4. There is no need to modify the Activity Name, use the default value and click the "finish" button.
Modify the layout file "activity_main.xml" in the res.layout directory
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="1"
android:text="Time" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock"
android:layout_column="2"/>
</TableRow>
<TableRow>
<TextView
android:text="First Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"/>
<EditText
android:width="200px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"/>
</TableRow>
<TableRow>
<TextView
android:text="Last Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"/>
<EditText
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--评分组件-->
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--确定按钮-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/button"
android:layout_column="2"/>
</TableRow>
</TableLayout>
Using Nexus S API 30 emulator.
The running screenshot is as follows:
Click to slide the number of stars.
Since the time is not set, the time is wrong.
Seven layout managers:
In an Android application, the user interface is built through View and ViewGroup objects. There are many types of Views and ViewGroups in Android, all of which inherit from the View class. The View object is the basic unit representing the user interface on the Android platform. The layout method refers to how a group of View elements are laid out. To be precise, it is how some Views contained in a ViewGroup are laid out. The View layout classes introduced here all directly or indirectly inherit from the ViewGroup class, as shown in the figure.
In fact, all layout methods can be classified into the five categories of ViewGroup, that is, the five direct subclasses of ViewGroup. Some other layouts extend from these five classes.