package com.test;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.TextView;
public class VerticalScrollTextView extends TextView
{
private int index;
private float mX,mY,middleY,DY;
private Paint mPaint,mPathPaint;
private ArrayList<Sentence> list;
public VerticalScrollTextView(Context context) {
super(context);
init();
}
public VerticalScrollTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public VerticalScrollTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init()
{
setFocusable(true);
//这里主要处理如果没有传入内容显示的默认值
if(list==null){
list=new ArrayList<Sentence>();
Sentence sen=new Sentence(0,"暂时没有通知公告");
list.add(0, sen);
}
//普通文字的字号,以及画笔颜色的设置
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setTextSize(16);
mPaint.setColor(Color.BLACK);
mPaint.setTypeface(Typeface.SERIF);
//高亮文字的字号,以及画笔颜色的设置
mPathPaint = new Paint();
mPathPaint.setAntiAlias(true);
mPathPaint.setColor(Color.RED);
mPathPaint.setTextSize(16);
mPathPaint.setTypeface(Typeface.SANS_SERIF);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(0xEFeffff);
Paint p = mPaint;
Paint p2 = mPathPaint;
p.setTextAlign(Paint.Align.CENTER);
if (index == -1)
return;
p2.setTextAlign(Paint.Align.CENTER);
canvas.drawText(list.get(index).getTitle(), mX, middleY, p2);
DY=p.getTextSize()*2;
float tempY = middleY;
for (int i = index - 1; i >= 0; i--) {
tempY = tempY - DY;
if (tempY < 0) {
break;
}
canvas.drawText(list.get(i).getTitle(), mX, tempY, p);
}
tempY = middleY;
for (int i = index + 1; i < list.size(); i++) {
tempY = tempY + DY;
if (tempY > mY) {
break;
}
canvas.drawText(list.get(i).getTitle(), mX, tempY, p);
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mX = w * 0.5f;
mY = h;
middleY = h * 0.5f;
}
private long updateIndex(int index) {
if (index == -1)
return -1;
this.index=index;
return index;
}
public void updateUI(){
new Thread(new updateThread()).start();
}
class updateThread implements Runnable
{
long time = 1000;
int i=0;
public void run() {
while (true) {
long sleeptime = updateIndex(i);
time += sleeptime;
mHandler.post(mUpdateResults);
if (sleeptime == -1)
return;
try {
Thread.sleep(time);
i++;
if(i==list.size())
i=0;
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Handler mHandler = new Handler();
Runnable mUpdateResults = new Runnable() {
public void run() {
invalidate();
}
};
public void setList(ArrayList<Sentence> list)
{
this.list = list;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
android 垂直滚动的TextView
共28个文件
class:11个
java:4个
png:3个
4星 · 超过85%的资源 需积分: 10 111 下载量 165 浏览量
2012-05-09
15:11:33
上传
评论 1
收藏 50KB RAR 举报
温馨提示
android 垂直滚动的TextViewandroid 垂直滚动的TextView
资源推荐
资源详情
资源评论
收起资源包目录
垂直滚动的TextView.rar (28个子文件)
VerticalScrollTextView_Demo
bin
classes.dex 7KB
VerticalScrollTextView_Demo.apk 16KB
com
test
R$layout.class 364B
VerticalScrolltextviewActivity.class 2KB
R$id.class 359B
R$drawable.class 370B
VerticalScrollTextView$1.class 643B
VerticalScrollTextView$updateThread.class 1KB
R$attr.class 310B
R.class 461B
R$string.class 397B
VerticalScrollTextView.class 4KB
Sentence.class 800B
resources.ap_ 11KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
values
strings.xml 204B
drawable-mdpi
icon.png 3KB
layout
main.xml 521B
assets
default.properties 362B
gen
com
test
R.java 730B
proguard.cfg 1KB
src
com
test
VerticalScrollTextView.java 3KB
VerticalScrolltextviewActivity.java 816B
Sentence.java 381B
.project 863B
.classpath 280B
AndroidManifest.xml 692B
共 28 条
- 1
skjlbhd2010
- 粉丝: 1
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页