永发信息网

android studio怎么实现字幕自动滚动

答案:2  悬赏:80  手机版
解决时间 2021-03-16 22:51
android studio怎么实现字幕自动滚动
最佳答案
这个Android字幕滚动类的自定义功能比较多,可定义当前滚动到结尾时的停顿时间,单位:毫秒,还可设置当前的滚动速度,值越小,速度越快。

主要实现代码如下:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

package com.tony.autoscroll;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class AutoScrollView extends ScrollView {
private final Handler handler = new Handler();
private long duration = 50;
private boolean isScrolled = false;
private int currentIndex = 0;
private long period = 1000;
private int currentY = -1;
private double x;
private double y;
private int type = -1;

public AutoScrollView(Context context) {
this(context, null);
}

public AutoScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public AutoScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean onTouchEvent(MotionEvent event) {
int Action = event.getAction();
switch (Action) {
case MotionEvent.ACTION_DOWN:
x=event.getX();
y=event.getY();
if (type == 0) {
setScrolled(false);
}
break;
case MotionEvent.ACTION_MOVE:
double moveY = event.getY() - y;
double moveX = event.getX() - x;
Log.d("test", "moveY = " + moveY + " moveX = " + moveX );
if ((moveY>20||moveY<-20) && (moveX < 50 || moveX > -50) && getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_UP:
if (type == 0) {
currentIndex = getScrollY();
setScrolled(true);
}
break;
default:
break;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent p_event)
{
Log.d("test", "onInterceptTouchEvent");
return true;
}

public boolean isScrolled() {
return isScrolled;
}

public void setScrolled(boolean isScrolled) {
this.isScrolled = isScrolled;
autoScroll();
}

public long getPeriod() {
return period;
}

public void setPeriod(long period) {
this.period = period;
}

public long getSpeed() {
return duration;
}

public void setSpeed(long speed) {
this.duration = speed;
}
public void setType(int type){
this.type = type;
}
private void autoScroll() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
boolean flag = isScrolled;
if (flag) {
//Log.d("test", "currentY = " + currentY + " getScrollY() = "+ getScrollY() );
if (currentY == getScrollY()) {
try {
Thread.sleep(period);
} catch (InterruptedException e) {
e.printStackTrace();
}
currentIndex = 0;
scrollTo(0, 0);
handler.postDelayed(this, period);
} else {
currentY = getScrollY();
handler.postDelayed(this, duration);
currentIndex++;
scrollTo(0, currentIndex * 1);
}
} else {
//currentIndex = 0;
//scrollTo(0, 0);
}
}
}, duration);
}
}
全部回答
按下按钮会触发listview滚动或停止。 实现该功能并不难,下面给出主要代码mainactivity.java ?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
聚星纳米汗蒸养生馆在哪里啊,我有事要去这个
野口纳豆激酶服用方式
有人说时间可以让人忘记一些事情 甚至包括一
小米max有时会自动重启怎么办
税控机扬天2020d 换什么显卡
想买一款不易刮花镜面的蓝宝石镜面手表,求推
我女朋友1995年农历二月甘三出生 请问2014年
m,i,u,c,s组成一个英语单词,包括汉语。
歌词baby why me后面是韩文 这首是什么歌
沈阳高考复读学校到底哪里比较不错呢?朋友们
猪笼草冬天南方怎么养
请教各位侠:内燃砖的掺煤比大概是多少?
晋升典当行在什么地方啊,我要过去处理事情
国内信封和国际信封的区别,它们有说明不同之
gta4 侠盗猎车手4改了commandline,谁知道改了
推荐资讯
人事部有哪些工作?
女朋友不喜欢接吻,讨厌口水怎麽办
七度空间特薄夜用卫生巾好用吗
请问 现在有多少人用索尼walkman听歌的吗?
广瑞汽车维修保养中心怎么去啊,有知道地址的
请问总共附魔45点物理攻击力,可以增加多少点
诺贝尔瓷砖(缙云康宁妇儿医院南)这个地址在什
母狗不是纯种黑贝公狗是纯种黑贝能卖多少钱
跪求~急 急 急在三国赵云传1 为什么 寻宝的
苹果电脑装windows8.1怎么激活工具
丈夫去世,车辆如何分配
《萧十一郎》中逍遥侯的本名叫什么?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?