Android TextView阴影效果及跑马灯效果

本文介绍如何使用Android TextView实现阴影效果及跑马灯效果。包括设置阴影颜色、模糊度、偏移量的方法,以及实现跑马灯效果的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android TextView阴影效果及跑马灯效果

项目场景:

Android TextView实现阴影效果及跑马灯效果


阴影效果:

首先需要设置阴影的颜色

android:shadowColor="@color/blue"

然后需要设置阴影模糊度

android:shadowRadius="3"

最后设置其偏移量即可

android:shadowDx="10"
android:shadowDy="10"

跑马灯效果:

首先需要设置其为单行显示并能够获取焦点,其次设置省略模式为marquee,最后设置循环模式为marquee_forever,具体设置如下:

android:singleLine="true"
android:focusable="true" 
android:focusableInTouchMode="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"

此时你会发现,跑马灯并不能正常的运行,因为TextView此时并没有自动获取焦点,这时只需要在TextView标签内添加即可。
<requestFocus/>

最终代码:

添加阴影及跑马灯后的最终代码如下:

<TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="center"
        android:shadowColor="@color/blue"
        android:shadowDx="10"
        android:shadowDy="10"
        android:shadowRadius="3"
        android:text="添加阴影及偏移 添加阴影及偏移 添加阴影及偏移 添加阴影及偏移"
        android:textColor="@color/black"
        android:textSize="30sp"
        android:textStyle="italic"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true">
<requestFocus/>
</TextView>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值