TestView

2021/8/12 6:07:55

本文主要是介绍TestView,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

基础属性:

1、layout_width: 组件的宽度

2、layout_height: 组件的高度

3、id: 为TextView设置一个组件id

4、text: 设置显示的文本内容

5、textColor: 设置字体颜色

6、textStyle: 设置字体风格,三个可选值:normal(无效果),bold(加粗),italic(斜体)

7、textSize: 字体大小,单位一般是用sp

8、background: 控件的背景颜色,可以理解为填充整个控件的颜色,可以是图片

9、gravity: 设置控件中内容的对齐方向,TextView中是文字,ImageView中是图片等等。

 

带阴影的TextView:

1、android:shadowColor:设置阴影颜色,需要与shadowRadius一起使用

2、android:shadowRadius:设置阴影的模糊程度,设为0.1就变成字体颜色了,建议使用3.0

3、android:shadowDx:设置阴影在水平方向的偏移,就是水平方向阴影开始的横坐标位置

4、android:shadowDy:设置阴影在竖直方向的偏移,就是竖直方向阴影开始的纵坐标位置

 

实现跑马灯效果的TextView

1、android:singleLine:内容单行显示

2、android:focusable:是否可以获取焦点

3、android:focusablelnTouchMode:用于控制视图在触摸模式下是否可以聚焦

4、android:ellipsize:在哪里省略文本

5、android:marqueeRepeatLimit:字母动画重复的次数

获取焦点的方式:

方法一:
android:clickable="true"
方法二(自定义TextView 调用isFocused()):
package com.fb.helloWorld;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import androidx.annotation.Nullable;

@SuppressLint("AppCompatCustomView")
public class MyTextView extends TextView {
    public MyTextView(Context context) {
        super(context);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean isFocused() { //获取焦点
        return true;
    }
}
方法三:
<requestFocus/>

 



这篇关于TestView的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程