UI界面和组件(一)

一、常用的UI组件:

TextView, EditText, Button, CheckBox, RadioGroup+RadioButton, ImageView...

二、使用范例如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SimpleComponentActivity"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tv_title"
        android:text="这是TextView的内容。"
        android:textSize="18sp"
        android:textStyle="bold"
        android:textColor="#ff0000"
        android:textAlignment="center"
        android:background="#999999"
        android:padding="20dp"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" />
    <EditText
        android:id="@+id/et_phone_number"
        android:inputType="phone"
        android:hint="请输入手机号码"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/btn_submit"
        android:text="提交"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <ImageView
        android:id="@+id/iv_image"
        android:src="@drawable/konodioda"
        android:layout_gravity="center"
        android:background="@android:drawable/picture_frame"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <LinearLayout
        android:layout_gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
             android:text="爱好:"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>

         <CheckBox
             android:id="@+id/cb_sing"
             android:text="唱"
             android:checked="true"

             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
         <CheckBox
             android:id="@+id/cb_dance"
             android:text="跳"

             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
         <CheckBox
             android:id="@+id/cb_rap"
             android:text="rap"

             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
         <CheckBox
             android:id="@+id/cb_basketball"
             android:text="篮球"

             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
        <Button
            android:id="@+id/btn_ok"
            android:text="确定"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>


        </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_gravity="center"

        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:text="性别:"
            android:layout_gravity="center"
            
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <RadioGroup
            android:id="@+id/rg_gender"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RadioButton
                android:id="@+id/rb_male"
                android:text="男"
                android:checked="true"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <RadioButton
                android:id="@+id/rb_female"
                android:text="女"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </RadioGroup>

    </LinearLayout>


</LinearLayout>

 

演示:

 

 

 

 

 

 

 

三、可创建资源文件夹drawable-hdpi来存放高dpi图片,实现对图片资源的分类管理,drawable-hdpi里的图片,仍然会在drawable中显示。

                              

 

 

posted @ 2021-01-08 14:55  Master_Sun  阅读(154)  评论(0编辑  收藏  举报