Android Studio学习之TextView

一、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"/>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值