a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統 > Android > 正文

Android實現字幕滾動的方法

2020-04-11 11:47:29
字體:
來源:轉載
供稿:網友

本文實例介紹了安卓Android實現字幕滾動效果的方法。主要是一個現成的Java類文件實現的,該程序由Android達人Tony編寫,本次是轉發,還望原作者Tony不要介意。這個Android字幕滾動類的自定義功能比較多,可定義當前滾動到結尾時的停頓時間,單位:毫秒,還可設置當前的滾動速度,值越小,速度越快。

主要實現代碼如下:

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;/** * @author Tony */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; /** * @param context */ public AutoScrollView(Context context) { this(context, null); } /** * @param context * @param attrs */ public AutoScrollView(Context context, AttributeSet attrs) { this(context, attrs, 0); } /** * @param context * @param attrs * @param defStyle */ 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;    }  /** * 判斷當前是否為滾動狀態 * @return the isScrolled */ public boolean isScrolled() { return isScrolled; } /** * 開啟或者關閉自動滾動功能 * @param isScrolled *      true為開啟,false為關閉 */ public void setScrolled(boolean isScrolled) { this.isScrolled = isScrolled; autoScroll(); } /** * 獲取當前滾動到結尾時的停頓時間,單位:毫秒 * @return the period */ public long getPeriod() { return period; } /** * 設置當前滾動到結尾時的停頓時間,單位:毫秒 * @param period *the period to set */ public void setPeriod(long period) { this.period = period; } /** * 獲取當前的滾動速度,單位:毫秒,值越小,速度越快。 * @return the speed */ public long getSpeed() { return duration; } /** * 設置當前的滾動速度,單位:毫秒,值越小,速度越快。 * @param speed *the duration to set */ 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); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: av在线一区二区三区 | 日韩精品免费观看 | 在线看免费观看日本 | 国产精品久久精品 | 色综合天天天天做夜夜夜夜做 | 成人免费视频www在线观看我 | 国产一区二区三区免费观看 | av日韩一区 | 在线观看一级片 | 一级黄色国产 | 不卡免费视频 | 精品久久久久久久久久久久久久 | 久久视频一区 | 婷婷综合 | 成人av观看 | 婷婷色国产偷v国产偷v小说 | 午夜视频| 午夜激情在线观看 | 亚洲人成中文字幕在线观看 | 欧美中文字幕 | 五月香婷婷 | 国产一区二区三区免费 | 黄色片在线免费观看 | 国产中文字幕在线 | 视频一区免费观看 | 亚洲三级免费观看 | 日韩城人网站 | www.78av| 日比视频网站 | 久久精品久久久 | 一级篇 | 日本成人黄色 | 国产亚洲精品一区二区 | 国内精品一区二区 | 能在线观看的黄色网址 | 特黄视频| www.日韩.com | 久久99精品久久久 | 黄色成人在线 | 91久久综合亚洲鲁鲁五月天 | 成人射区 |