textView就像是一个容器,我们要把一些控件放入这些容器当中
android:layoutwidth=””:行宽,单位可用dp
android:layout_height=””:行高,单位可用dp
android:id=”@+id/XXX”:设置一个组件id(后端可用TextView tv_one = findViewById(R.id._tv_one);调用)
android:text=”@string/XXX”设置显示的文本内容(锁定id后可设置其text:tv_one.setText(“hello”);)
android:textColor=”XXXX”字体颜色
android:textStyle=”XXX” normal(无效果),bold(加粗),italic(斜体)
android:textSize=”XXsp” 字体大小,单位一般用sp
android:background=”@color/white”控件的背景颜色,可以理解为填充整个容器的颜色,可以是图片等
android:gravity=””设置空间中内容的对齐方向,TextView中是文字,imageView中是图片等等
android:shadowColor=”XXX”设置阴影颜色,需要与shadowRadius一起使用
android:shadowRadius=”3.1”设置阴影的模糊程度,设置为0.1就变成字体颜色,建议设置为3.0
android:shadowDx=”10”设置阴影在水平方向的偏移程度
android:shadowDy=”10”设置阴影在竖直方向的偏移程度
android:singleLine=”true” 内容单行显示
android:focusable=”true”是否可以获取焦点
android:focusableInTouchMode=”true”用于控制试图在触摸模式下是否可以聚焦
android:ellipsize=”end”在哪里可以省略文本
android:marqueeRepeatLimit=”marquee_forever”字幕动画重复的次数
属性:
wrap_content,自动分配宽度,不会超过容器总宽度
match_parent,容器有多宽它就有多宽
代码示例
<?xml version=”1.0” encoding=”utf-8”?>
android:layout_height=”match_parent”
android:orientation=”vertical”
xmlns:android=”http://schemas.android.com/apk/res/android">
<TextView<br /> android:id="@+id/tv_one"<br /> android:layout_width="wrap_content"<br /> android:layout_height="200dp"<br /> android:textColor="#FF0000FF"<br /> android:textSize="30sp"<br /> android:background="@color/white"<br /> android:shadowColor="@color/black"<br /> android:singleLine="true"<br /> android:shadowDx="10"<br /> android:shadowDy="10"<br /> android:shadowRadius="3.1"<br /> android:gravity="center_vertical"<br /> android:text="@string/tv_one"<br /> android:textStyle="bold"<br /> android:focusable="true"<br /> android:focusableInTouchMode="true"<br /> android:ellipsize="marquee"<br /> android:clickable="true"<br /> android:marqueeRepeatLimit="marquee_forever"<br /> />