- 浏览: 115984 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zhifeiji512:
George_ghc 写道第一段代码给cursor赋值第二段代 ...
Android中Cursor关闭的问题
参考文章:
- Android2.2 API 中文文档系列(1) —— TextView
- [Android1.5]TextView跑马灯效果
- addStatesFromChildren 和跑马灯
- TextView总是显示跑马灯效果
思想介绍:
TextView自带跑马灯的效果,需要设置一下TextView的属性,把显示模式改为“跑马灯”。设置滚动次数。
这些都还不够,因为TextView的跑马灯跑起来,需要此textView得到焦点。所以要想个办法解决一下,让他总是滚动。
简要步骤:
在包中新建一个类,继承TextView。重写isFocused方法,这个方法默认行为是,如果TextView获得焦点,方法返回true,失去焦点则返回false。跑马灯效果估计也是用这个方法判断是否获得焦点,所以把它的返回值始终设置为true。
示例1:
Java语言: AlwaysMarqueeTextView 类
public class AlwaysMarqueeTextView extends TextView { public AlwaysMarqueeTextView(Context context) { super(context); } public AlwaysMarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; }
在布局XML文件中加入这么一个AlwaysMarqueeTextView,这个加入方法也是刚刚学的。
<com.examples.AlwaysMarqueeTextView
android:id=“@+id/AMTV1″
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:lines=“1″
android:focusable=“true”
android:focusableInTouchMode=“true”
android:scrollHorizontally=“true”
android:marqueeRepeatLimit=“marquee_forever”
android:ellipsize=“marquee”
android:background=“@android:color/transparent” />
ellipsize属性设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。
focusable属性
自己猜测的,应该是能否获得焦点,同样focusableInTouchMode应该是滑动时能否获得焦点。
示例2:
组合View的问题:
XML语言: 组合View <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="center_vertical" android:background="@drawable/f_background" android:layout_width="fill_parent" android:focusable="true" android:layout_height="50px"> <TextView android:id="@+id/info_text" android:focusable="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="test marquee ... " android:textColor="@color/black" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="3" android:textSize="18sp" /> <TextView android:id="@+id/date_texfocusablet" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:textColor="@color/gray" android:text="2011/04/01" android:textSize="12sp"/> </LinearLayout >
上面示例中2个TextView组合为一个View,由于设置了LinearLayout为focusable而TextView就没法取得焦点了,这样 这个TextView的跑马灯效果就显示不出来,就算你也设置TextView的 android:focusable= "true" 也是 没用的. 这个时候就要使用addStatesFromChildren 这个属性了,在LinearLayout中设置这个属性,然后设置TextView的focusable= "true" 就可以了.关于 addStatesFromChildren的说明:
Sets whether this ViewGroup's drawable states also include its children's drawable states.
发表评论
-
repo用法
2012-03-16 14:24 1208repo用法(转载) http://blogold ... -
Git使用指南
2012-03-15 14:43 8511.创建目录 $ git config --glo ... -
关于Android的多种屏幕支持
2011-12-14 14:23 1224首先是几个基本概 ... -
android ListView 修改背景
2011-12-14 09:39 1828修改listview时存在的 ... -
详解android:scaleType属性
2011-11-28 17:09 6360android:scaleType是控制图片如何res ... -
Android使用AIDL设计和调用远程接口
2011-11-24 18:14 3986在Android中, 每个应 ... -
Android开发 系统应用调用,Intent使用总结
2011-11-09 09:48 1301转载来源网上资料。 显示网页: 1. Ur ... -
ListView结合ContextMenu 获取点击项的Position
2011-11-07 17:35 1428ContextMenu称为上下文菜单,一般在控件上长按时 ... -
List of Android MIME types and Uri's
2011-11-07 16:35 1575This is a list of URIs that can ... -
隐藏输入法
2011-11-07 14:16 804在manifest里设置,android:windowSoft ... -
SlidingDrawer 使用
2011-10-28 17:51 3965关于SlidingDrawer控件 1.重要属性 ... -
Android通知及receiver
2011-10-24 15:09 37681. BroadcastReceiver Broadc ... -
Notification
2011-10-21 16:49 1547可以给Notification设置缺省的表现形式: ... -
Android获取其他包的Context实例
2011-10-20 11:17 837Android中有Context ... -
Android 中Message,MessageQueue,Looper,Handler详解+实例
2011-10-18 13:23 884一、几个关键概念 ... -
Activity 的生命周期 以及 横屏竖屏切换时 Activity 的状态变化
2011-10-18 13:21 1042转自:http://www.blogjava.ne ... -
免费的Android UI库及组件推荐
2011-10-18 13:10 2969转自:http://www.iteye.com/news/22 ... -
众多Android 开源项目推荐,给力工作给力学习
2011-10-18 11:54 626转自:http://www.cnblogs.com/Terry ... -
下拉刷新
2011-10-18 11:10 753下拉刷新 参考代码 https://gith ... -
canvas.translate(x,y)理解
2011-10-17 15:59 2647translate(float x,float y)函数是将整 ...
相关推荐
android textview 无焦点 跑马灯 水平滚动 代码 和apk程序
android垂直滚动的textview,仿跑马灯效果
一个垂直滚动TextView跑马灯效果的Demo,效果很棒
主要为大家详细介绍了Android自定义textview实现竖直滚动跑马灯效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
android自定义横向跑马灯TextView(两种,即使一个字符也能跑马灯)
android三种方式实现TextView跑马灯效果
本文实例讲述了Android基于TextView属性android:ellipsize实现跑马灯效果的方法。分享给大家供大家参考,具体如下: Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1、android:ellipsize=”marquee...
TextView滚动,跑马灯效果终极解决方案.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
TextView跑马灯、闪烁和跳动动画,跳动有左右跳动,上下跳动,还有波浪形从左往右跳动
本例使用两种方法实现android中TextView跑马灯(循环滚动)的效果
可以调文字滚动速度的跑马灯 。
textview跑马灯效果终极实验,解决你对实现效果的疑问,viewgroup嵌套对跑马灯效果是否有影响,为什么有时候同样的设置对textview1起作用,对textview2不起3作用。
自定义View—实现滚动TextView(跑马灯)效果源码,教程在http://blog.csdn.net/u012933743/article/details/46310225 如有不懂 可以评论提问
跑马灯效果其实就是当文字超过TextView控件宽度的时候,使用滚动的方式显示出来: 方法1:(直接xml搞定) Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1、android:ellipsize=”marquee”; 2...
只需粘贴run_led.java 并进行一些基本的设置即可 值得注意的是 使用该控件的时候,这句需要根据自己的路径来更改,初学者留一下,不然会崩的。
项目中欢迎词多的时候需要实现上下滚动,了解到在android中TextView可以轻松实现横向跑马灯效果,但是对垂直滚动没有直接的支持方法,于是百度上谷歌,谷歌上百度,最终还是没有发现一个拿来即用的demo,呵呵,于是...
textview显示跑马灯效果,使用的是继承的方法onDraw不停地绘制 优点: 1.文字长短不限哦 2.不用非得获取焦点哦
自定义的Android滚动TextView 附件是一个可以在Eclipse运行起来的Android工程,是基于SDK19(即4.4的),如果机器上没有4.4,导入工程后记得修改sdk版本 代码有较为详细的注释 爱我中华!