当前位置: 移动技术网 > IT编程>移动开发>Android > Android UI实现单行文本水平触摸滑动效果

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

企业供求黄页,高安中学校友录,代嫁舞姬

本文实例为大家分享了单行文本水平触摸滑动效果,通过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);

代码示例:

<edittext
 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" />

附上下载地址:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网