**
Android开发入门学习的第一个控件——TextView
学习控件必然要了解相应控件的基本属性,接下来对TextView属性的整理。
学习属性的过程中建议使用Android Studio中的Split,在写代码的同时观察布局或控件的变化。
TextView常用属性
属性 | 说明 |
---|---|
android:layout_width | 设置文本框宽度,可选wrap_content(根据文本内容自动分配大小),match_parent (默认铺平),或自定义大小 |
android:layout_height | 设置文本框高度,可选值与宽度一样 |
android: text | 设置文本内容 |
android:gravity | 设置文本的对齐方式,可选值top,right,left,center等 |
android:textSize | 设置字体大小(一般使用单位为sp) |
android:textColor | 设置文本颜色 |
android:background | 设置背景颜色 |
android:textStyle | 设置字体风格,可选值normal(无效果),bold(加粗),italic(斜体) |
例如:
代码如下:
<?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"