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>
版权声明:
作者:瑞羽云
链接:https://www.ruiyuyun.cn/archives/391.html
来源:瑞羽云
本站部分内容源于互联网,如果侵犯了您的权利,请发邮件告之,邮箱zcrvip@vip.qq.com
如果可以,希望您在分享的时候直接分享本网址,整理不易,谢谢配合!
THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录