Android TextView 中文本横向滚动效果实现
16lz
2021-01-23
字面意思可能不太好理解,那就来个动图吧
以上效果是来自第三方库 MarqueeView
如果想了解更多请到 GitHub 搜索 跑马灯
使用系统的 TextView 实现
- 自定义一个TextView
貌似也可以不用自定义 ,直接在 xml 中设置
isFocused = true
, 待验证?
public class MarqueeTextView extends AppCompatTextView { public MarqueeTextView(Context context) { super(context); } public MarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public boolean isFocused(){ return true; }}
- 在 xml 中设置相应的属性
<com.xxxx.xxxx.xxx.widget.MarqueeTextView android:id="@+id/post_content_tv" android:layout_width="200dp" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" />
主要的属性介绍
android:layout_width="200dp"
表示超过这个范围的文字才会滚动
android:focusable="true"
和android:focusableInTouchMode="true"
需要设置让其 获取焦点 方可滚动
android:singleLine="true"
设置让其单行一直滚动
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
更多相关文章
- Android如何获得系统(system)权限 !!!
- 【摘录】 Android中如何修改系统时间(应用程序获得系统权限)
- Android Layout 布局 && Android自带样式(theme)&& CheckBox样例 &
- 为android系统添加USB AUDIO设备的放音和录音功能
- Android 7.1.1中SystemProperties 设置属性无限问题分析
- Android屏幕截图实现方式 系统截屏源码分析和三指截屏
- android 自定义xml属性
- Android系统添加全局快捷键的方法