Android development learning experience (3)

现在我对xml有了更近一步的了解的,在使用过不少APP后我觉得UI设计的好坏直接影响用户数量的,现在总结一下常用控件的使用方法。MianActivity代码如下:

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wukong"
>
<TextView
android:id="@+id/hellow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="225dp"
android:text="加油"
android:textColor="#ffff0000"
android:textSize="40dp" />
<Button
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/hellow"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="67dp"
android:background="@drawable/button" />
</RelativeLayout>

The running effect is shown in Figure 1.

RelativeLayout supports controls that can set their own positions, while LinearLayout does not. The basic usage of each control is to set an ID first, and then set the length and width. You can further set the details yourself.

2. All images used by the APP should be added to the drawable folder under res, and android:background=”@drawable/image name used” is used to set the background of the icon or interface.

3. The official recommends using match_parent, which means that the size of the current control is the same as the parent layout.

4. After adding the button in the xml, you should also add a click event listener in the Activity to realize the function of the button. When you press it, the onClick() method of the listener will be executed.

5. There are several controls that have not written detailed code, such as ImageView is a control that displays pictures on the interface. ProgressBar displays a progress bar on the interface. AlertDialog is a prompt dialog box that pops up on the current interface.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324588385&siteId=291194637