一、TextView使用
TextView常用属性
1.id
2.layout_width
3.layout_height
4.layout_gravity
5.text
6.textColor
7.textSize
8.layout_marginTop
<TextView
android:id="@+id/tv_readMenu_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="hello world!"
android:textColor="@color/black"
android:textSize="20sp"
layout_marginTop="15dp"/>
效果:
二、实现中划线与下划线效果:
1.在所对应的activity中声明该控件,并找到该控件。
2.会有一点锯齿,因此要去除锯齿
public class ReadMenu extends AppCompatActivity {
//声明控件
private TextView mTv4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_menu);
//找到控件
mTv4 = findViewById(R.id.tv_readMenu_4);
// //实现中划线
// mTv4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
//实现下划线
mTv4.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
//去除锯齿
mTv4.getPaint().setAntiAlias(true);
}
}
三、实现跑马灯
1.跑马灯需要获取焦点
<TextView
android:id="@+id/tv_readMenu_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world "
android:textColor="@color/black"
android:textSize="20sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"/>