1月14日安卓实现跑马灯文字效果

1.红色的字体阴影效果
在这里插入图片描述

    android:shadowColor="@color/red"
    //单独设置阴影颜色没有效果,需要和shadowRadius结合使用
    android:shadowRadius="3.0"
    //一般设置为3.0才有效果,设置为0.1效果不明显,0.1为字体颜色
    android:shadowDx="-10.0"
    android:shadowDy="-10.0"       

这里面的负号代表红色阴影在左上方,不加负号则阴影就在右下方,默认的x,y轴向右向下。

2.文字跑马灯显示

        android:singleLine="true"
        //内容单行显示,省略号……
        android:ellipsize="marquee"
        //在哪里省略文本,省略号在哪
        android:marqueeRepeatLimit="marquee_forever"
        //字幕动画重复的次数
        android:focusable="true"
        //是否可以获取焦点
        android:focusableInTouchMode="true"
        //视图在触摸模式下聚焦

方法一:
要是发现文字没有跑马灯显示,可设置点击事件
android:clickable=“true”

方法二:
自定义一个textview
public class MyTextView extends TextView
自动创建三个点击红色灯泡
在这里插入图片描述

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;
    }
}

TextView改为全局的包名
在这里插入图片描述
方法三:
请求焦点,加上一句

<TextView
        android:id="@+id/tv_one"
        android:text="@string/tv_one"
        android:textColor="@color/black"
        android:textStyle="bold"
        android:textSize="30sp"
        android:gravity="center"
        android:shadowColor="@color/red"
        android:shadowRadius="3.0"
        android:shadowDx="-10.0"
        android:shadowDy="-10.0"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="match_parent"
        android:layout_height="200dp">
        <requestFocus/>
    </TextView>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值