TextView:文本框容器
一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第2天,点击查看活动详情。
-
android:id:容器id @+id/容器id
- 能被 java 获取并对容器进行操作
-
android:layout_width:宽度
- match_parent:屏幕最长宽度
- wrap_content:按照内容宽度
-
android:layout_height:高度
- match_parent:屏幕最长高度
- wrap_content:按照内容高度
-
android:background:容器背景颜色
- 一般会把背景资源放在 res 包下的 colors.xml 中 通过 @color/colorName 来获取
-
android:gravity:容器内内容的排布
- center:居中
- left:左对齐
- right:右对齐
- bottom:最下
- top:最上
-
android:text:容器内的文本 一般会把文本资源放在 res 包下的 strings.xml 中 通过 @string/stringName 来获取
-
android:textColor:文本字体颜色
- 一般会把字体颜色资源放在 res 包下的 colors.xml 中通过 @color/colorName 来获取
-
android:textSize:文本字体大小
- 一般用 ‘sp’ 单位
-
android:textStyle:文本字体类型
- bold:加粗
- italic:倾斜
- normal:默认正常
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- 文本框容器、字体 -->
<!--
TextView:文本框容器
android:id:容器id @+id/容器id
能被 java 获取并对容器进行操作
android:layout_width:宽度
match_parent:屏幕最长宽度
wrap_content:按照内容宽度
android:layout_height:高度
match_parent:屏幕最长高度
wrap_content:按照内容高度
android:background:容器背景颜色
一般会把背景资源放在 res 包下的 colors.xml 中
通过 @color/colorName 来获取
android:gravity:容器内内容的排布
center:居中
left:左对齐
right:右对齐
bottom:最下
top:最上
android:text:容器内的文本
一般会把文本资源放在 res 包下的 strings.xml 中
通过 @string/stringName 来获取
android:textColor:文本字体颜色
一般会把字体颜色资源放在 res 包下的 colors.xml 中
通过 @color/colorName 来获取
android:textSize:文本字体大小
一般用 ‘sp’ 单位
android:textStyle:文本字体类型
bold:加粗
italic:倾斜
normal:默认正常
-->
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@color/purple_200"
android:gravity="center"
android:text="@string/tv1"
android:textColor="@color/black"
android:textSize="50sp"
android:textStyle="normal" />
</LinearLayout>
文本框内容阴影
-
android:shadowDx:阴影和文本内容的x轴偏移
- ‘+’ 是向右偏移,‘-’ 是向左偏移。具体写法是:‘10’ ‘-12’
-
android:shadowDy:阴影和文本内容的y轴偏移
- ‘+’ 是向下偏移,‘-’ 是向上偏移。具体写法是:‘10’ ‘-12’
-
android:shadowColor:阴影的颜色
- 一般会把阴影颜色资源放在 res 包下的 colors.xml 中通过 @color/colorName 来获取
-
android:shadowRadius:阴影半径/阴影虚幻程度
- 只能输入正数。具体写法:‘12’ ‘1.10’ ‘9.911‘
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--文本框内容阴影-->
<!--
android:shadowDx:阴影和文本内容的x轴偏移
‘+’ 是向右偏移,‘-’ 是向左偏移。具体写法是:‘10’ ‘-12’
android:shadowDy:阴影和文本内容的y轴偏移
‘+’ 是向下偏移,‘-’ 是向上偏移。具体写法是:‘10’ ‘-12’
android:shadowColor:阴影的颜色
一般会把阴影颜色资源放在 res 包下的 colors.xml 中
通过 @color/colorName 来获取
android:shadowRadius:阴影半径/阴影虚幻程度
只能输入正数。具体写法:‘12’ ‘1.10’ ‘9.911‘
-->
<TextView
android:id="@+id/tv_2"
android:layout_width="match_parent"
android:layout_height="278dp"
android:background="@color/purple_200"
android:gravity="center"
android:text="@string/tv1"
android:textColor="@color/black"
android:textSize="50sp"
android:textStyle="normal"
android:shadowDx="10"
android:shadowDy="-10"
android:shadowColor="@color/red"
android:shadowRadius="12" />
</LinearLayout>