1.常用控件的使用方法
1.1 TextView
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="24sp"
android:textColor="#00ff00"
android:text="this is TextView"
/>
1.1.1 android:id="@+id/text_view" : 定义TextView的Id
1.1.2 android:layout_width="match_parent":指定控件的宽度
1.1.3 android:layout_height="wrap_content":指定控件的高度
可选值:match_parent:表示让到当前控件的大小和父布局的大小一样,由父布局来决定当前控件的大小(推荐)
fill_parent:与match_parent意义相同
wrap_content:表示让当前控件的大小能够刚好包含住里面的内容,也就是由控件内容决定当前控件的大小。
1.1.4 android:gravity="center":指定文字的对齐方式,可选值top、bottom、left、right、center等,可以用“|”指定多个值。
1.1.5 android:textSize="24sp": 指定文字的大小
1.1.6 android:textColor="#00ff00": 指定文字的颜色
1.1.7 android:text="this is TextView":指定TextView中显示的文本内容
1.2 Button
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:textAllCaps="false"
/>
1.2.1 android:textAllCaps="false":Button控件的所有英文字母自动进行大写转换,如果想禁用这种特性,设置textAllCaps为false即可。
1.3 EditText 允许用户在控件里输入和编辑内容,并可以在程序中对这些内容进行处理。
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something here"
/>
1.3.1 android:hint="Type something here":指定一段提示性的文本