失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android 单行文本滚动 Android UI实现单行文本水平触摸滑动效果

android 单行文本滚动 Android UI实现单行文本水平触摸滑动效果

时间:2021-08-30 20:35:55

相关推荐

android 单行文本滚动 Android UI实现单行文本水平触摸滑动效果

本文实例为大家分享了单行文本水平触摸滑动效果,通过edittext实现textview单行长文本水平滑动效果。

下一篇再为大家介绍 多行文本折叠展开效果,自定义布局view实现多行文本折叠和展开。

1.初衷

最近做应用的时候有用到textview单行长文本,当文本内容过长时候又想实现触摸水平滑动效果。网上找了很多,都没有看到有效解决方案。

其中,看到最常见的也是最笨拙滴采用重写textview并继承实现touch 和 gesture手势。个人觉得很麻烦。

后来经提醒发现了其实最简单的方案:

直接使用edittext就好了。 因为edittext需要编辑和移动光标的缘故,使得它是可以水平滑动的。因此我们只需要设置其为透明背景,并且不可以获得焦点。

效果图:

2.具体实现

定义edittext,并设置背景透明,不能获得焦点。

android:background=”@android:color/transparent”

android:focusable=”false”

(注:不能使用 editable=“false”,因为这样就不能编辑滑动。而通过使用 focusable=”false” 同样不可编辑同时可以滑动)

3.补充

补充一点,要隐藏光标,只用设置

android:cursorvisible=”false”//隐藏或

setcursorvisible(false);

代码示例:

android:id="@+id/tt"

android:layout_width="0dip"

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_margin="15dip"

android:background="@android:color/transparent"

android:focusable="false"

android:singleline="true"

android:cursorvisible="false"

android:text="简易实现 textview单行文本水平触摸滑动效果。简易实现 textview单行文本水平触摸滑动效果。简易实现 textview单行文本水平触摸滑动效果"

android:textcolor="#000"

android:textsize="20dip" />

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

如果觉得《android 单行文本滚动 Android UI实现单行文本水平触摸滑动效果》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。