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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

Qiaoidea   2021-03-22 我要评论
想了解Android UI实现单行文本水平触摸滑动效果的相关内容吗,Qiaoidea在本文为您仔细讲解Android文本水平触摸滑动的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,UI水平触摸滑动,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);

代码示例:

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

附上下载地址:http://xiazai.jb51.net/201610/yuanma/Androidtouchmove(jb51.net).rar

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们