Android常用控件笔记

    技术2024-08-19  62

    控件是界面组成的主要元素,是与用户进行直接交互的。 TextView是用于显示文字(字符串)的控件,可在代码中通过设置属性改变文字的大小、颜色、样式等功能

    <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World! " android:textColor="#000000" android:textSize="25sp" android:gravity="center" />

    EditText继承自TextView,可以进行编辑操作,将用户信息传递给Android程序。还可以为EditText控件设置监听器,用来测试用户输入的内容是否合法。

    <EditText android:layout_width="match_parent“ android:layout_height="wrap_content“ android:hint="请输入姓名" android:maxLines="2" android:textColor="#000000" android:textSize="20sp" android:textStyle="italic" />

    Button是按钮,是用于响应用户的一系列点击事件,使程序更加流畅和完整。

    <Button android:id="@+id/btn" android:text="按钮" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="click" />

    ImageView是视图控件,它继承自View,其功能是在屏幕中显示图像。ImageView类可以从各种来源加载图像(如资源库或网络),并提供缩放、裁剪、着色(渲染)等功能。

    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg" /> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@android:drawable/sym_def_app_icon"/>
    Processed: 0.010, SQL: 9