listview实现跑马灯效果,和焦点获取
来源:互联网 发布:ar2220 s网络配置实例 编辑:程序博客网 时间:2024/06/01 08:46
ListView中经常需要让条目出现动画效果,跑马灯就是一种。
listview可以基于万能适配器开发,地址:
http://blog.csdn.net/lmj623565791/article/details/38902805。
如果要将整个listview都进行跑马灯比较容易。
首先自定义一个View,叫ItemTextView,代码如下:
package com.example.list;import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.TextView;public class ItemTextView extends TextView { public ItemTextView(Context context) { super(context); } public ItemTextView(Context context, AttributeSet attrs) { super(context, attrs); } public ItemTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(focused, direction, previouslyFocusedRect); }}
然后在xml文件的Listview中填入android:focusable=”true”;保持焦点。
在item.xml中需要加入android:singleLine=”true”
和android:ellipsize=”marquee”,也可以加入其他跑马灯属性,比如跑马灯的次数等android:marqueeRepeatLimit=”marquee_forever”。
这样就可以整个listview都开始跑马灯效果了。
但是如何让选中的item进行跑马灯,选中另一个,上一个不进行动画小工呢?
这时候在MainActivity中需要添加两个方法:
mListView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) { if(position == id){ mTextView = (TextView) view.findViewById(R.id.tv_describe); view.isFocusableInTouchMode(); view.requestFocusFromTouch(); mTextView.setEllipsize(TruncateAt.MARQUEE); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); mListView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { }else{ mTextView.setEllipsize(TruncateAt.END); //这里可以选择别的样式,需要将原来在item.xml文件中的android:ellipsize="marquee"去掉。 } } }); }
这样就实现了点击哪个item哪个动,其他不动的效果。
0 0
- listview实现跑马灯效果,和焦点获取
- TextView实现跑马灯效果(不获取焦点)
- TextView实现跑马灯效果,不用获取焦点
- Android中TextView不获取焦点可以实现跑马灯的效果
- Android:TextView不获取焦点可以实现跑马灯的效果
- 不用获取焦点也可实现跑马灯效果的Textview
- TextView始终获取不到焦点,导致无法实现跑马灯效果
- Android中TextView不获取焦点可以实现跑马灯的效果
- Android中TextView不获取焦点可以实现跑马灯的效果
- ListView 中的TextView实现跑马灯效果
- ListView 中的TextView实现跑马灯效果
- ListView 中的TextView实现跑马灯效果
- ListView 中的TextView实现跑马灯效果
- 使用ListView实现垂直跑马灯效果
- Android 自定义View实现跑马灯效果。没有任何焦点和长度限制。
- TextView不用获取焦点也能实现跑马灯
- TextView不用获取焦点也能实现跑马灯
- TextView不用获取焦点也能实现跑马灯
- 带参数的Fragment
- A2W和W2A :很好的多字节和宽字节字符串的转换宏
- UI控件--推送,以及Block块
- dedecms如何在列表页调出文章内容【body字段】
- Python 函数之函数定义、调用、传参
- listview实现跑马灯效果,和焦点获取
- 文章标题
- Swift Object-c 相互调用
- LeetCode-Number of Digit One(编程之美-1的数目)
- HDOJ5305 Friends(dfs)
- 150829_理论_屏幕适配
- 关于匿名内部类,非静态内部类会造成内存泄露的隐患。
- linux环境下LNMP和mantis的配置笔记
- zabbix如何实现微信报警