laogui 发表于 2023-3-15 16:49:29

【EasyClick】【安卓UI】XML 基础教程~XML扫盲

XML 基础教程(XML扫盲)
原教程地址:原生UI 扫盲篇


XML 文件说明XML 指可扩展标记语言(eXtensible Markup Language)。
资料:xml菜鸟教程例子<?xml version="1.0" encoding="utf-8"?>
<!-- 标签头-->
<a>
    <!-- 子标签头 -->
    <b>
      <c>
      </c>
    </b>
   
    <!-- 子标签尾 -->
   
    <!-- 子标签头-->
    <b1>
      <!-- 子标签头-->
      <c>
      </c>
      <!-- 子标签尾-->
    </b1>
    <!-- 子标签尾-->
    <!-- 自闭合标签 -->
    <d />
</a>
<!-- 标签尾-- >
EasyClick 标准格式

<?xml version="1.0" encoding="UTF-8" ?><!-- 第一行声明是个xml 文件 编码UTF-8 -->

<ScrollView
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xsi:noNamespaceSchemaLocation="layout.xsd"
    android:layout_height="match_parent"
    android:layout_width="match_parent" >
    <LinearLayout
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      android:orientation="vertical"
      android:padding="20dp">
      <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="表单开始,设置tag属性,用于在代码里面获取对应的值"/>


      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="姓名: "/>

            <EditText android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:tag="name"
                      android:hint="请输入姓名"/>

      </LinearLayout>

      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="年龄: "/>

            <EditText android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:tag="age"
                      android:hint="请输入年龄"/>

      </LinearLayout>


      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="性别: "/>

            <Spinner android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:tag="sex"
                     android:text="男同学|女同学"/>

      </LinearLayout>


      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="喜欢玩"/>

            <EditText android:layout_width="100dp"
                      android:layout_height="wrap_content"
                      android:gravity="center_horizontal"
                      android:tag="a1"
                      android:hint="什么"/>
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="和"/>
            <EditText android:layout_width="100dp"
                      android:gravity="center_horizontal"
                      android:layout_height="wrap_content"
                      android:tag="a2"
                      android:hint="什么"/>
      </LinearLayout>


      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="爱      好: "/>
            <LinearLayout android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_width="match_parent">
                <CheckBox android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:tag="music"
                        android:text="听音乐"/>
                <CheckBox android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:tag="sing"
                        android:text="唱歌"/>
                <CheckBox android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:tag="dance"
                        android:text="跳舞"/>
            </LinearLayout>

      </LinearLayout>


      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center"
                      android:text="所在年级: "/>
            <RadioGroup android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_width="match_parent">
                <RadioButton android:layout_width="match_parent"
                           android:layout_height="wrap_content"
                           android:tag="one"
                           android:text="一年级"/>
                <RadioButton android:layout_width="match_parent"
                           android:layout_height="wrap_content"
                           android:tag="two"
                           android:text="二年级"/>
                <RadioButton android:layout_width="match_parent"
                           android:layout_height="wrap_content"
                           android:tag="three"
                           android:text="三年级"/>
            </RadioGroup>

      </LinearLayout>
      <LinearLayout android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:gravity="center_vertical"
                      android:layout_width="match_parent">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:gravity="center_vertical"
                      android:text="备注: "/>

            <EditText android:layout_width="match_parent"
                      android:layout_height="200dp"
                      android:tag="mark"
                      android:minHeight="100dp"
                      android:maxLines="1000"
                      android:hint="备注"/>

      </LinearLayout>
    </LinearLayout>
</ScrollView>


EasyClick 官方标准解释第一行是必须有的。否则Android无法解析布局文件这表示是一个xml 格式的文件 编码UTF-8 。<!-- 第一行声明是个xml 文件 编码UTF-8 -->
<?xml version="1.0" encoding="UTF-8" ?>Copy


第二行的标签
形如下面的xml代码<ScrollView
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:android="http://schemas.android.com/apk/res/android"
      xsi:noNamespaceSchemaLocation="layout.xsd"
      android:layout_height="match_parent"
      android:layout_width="match_parent" >
    <!-- 这里面写子布局-->
    <LinearLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:padding="20dp">
                <!-- 这里面写子布局或者 子控件-->
    </LinearLayout>
</ScrollView>


标准格式说明:

**** Hidden Message *****

靖訸 发表于 2023-3-22 11:59:28

看看               

dddd 发表于 2023-10-12 15:35:20

快快快速速速速速速所所所所所所所所所所所速速所所所所

lc2150827388 发表于 2024-1-5 22:11:53

1111111111111111111111111
页: [1]
查看完整版本: 【EasyClick】【安卓UI】XML 基础教程~XML扫盲