直播系統原始碼,圖片一直滾動,迴圈滾動,豎向和橫向
直播系統原始碼,圖片一直滾動,迴圈滾動,豎向和橫向實現的相關程式碼
豎向:
public class LoopScrollView extends View { private final int speed; private final Bitmap bitmap; private Rect clipBounds = new Rect(); private float offset = 0; private boolean isStarted; public LoopScrollView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ParallaxView, 0, 0); try { speed = ta.getDimensionPixelSize(R.styleable.ParallaxView_speed, 10); bitmap = BitmapFactory.decodeResource(getResources(), ta.getResourceId(R.styleable.ParallaxView_src, 0)); } finally { ta.recycle(); } // start(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(bitmap.getWidth(), MeasureSpec.getSize(heightMeasureSpec)); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (canvas == null) { return; } canvas.getClipBounds(clipBounds); float normalizedOffset = offset; float layerHeight = bitmap.getHeight(); if (offset <= -layerHeight) { offset += (floor(abs(normalizedOffset) / layerHeight) * layerHeight); } float top = offset; while (top < clipBounds.height()) { canvas.drawBitmap(bitmap, 0, getBitmapTop(layerHeight, top), null); top += layerHeight; } if (isStarted) { offset -= speed; postInvalidateOnAnimation(); } } private float getBitmapTop(float layerHeight, float top) { float bitmapTop = top; if (speed < 0) { bitmapTop = clipBounds.height() - layerHeight - top; } return bitmapTop; } /** * Start the animation */ public void start() { if (!isStarted) { isStarted = true; postInvalidateOnAnimation(); } } /** * Stop the animation */ public void stop() { if (isStarted) { isStarted = false; invalidate(); } } }
橫向:
public class LoopScrollView extends View { private final int speed; private final Bitmap bitmap; private Rect clipBounds = new Rect(); private int offset = 0; private boolean isStarted; public LoopScrollView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ParallaxView, 0, 0); try { speed = ta.getDimensionPixelSize(R.styleable.ParallaxView_speed, 10); bitmap = BitmapFactory.decodeResource(getResources(), ta.getResourceId(R.styleable.ParallaxView_src, 0)); } finally { ta.recycle(); } start(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), bitmap.getHeight()); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (canvas == null) { return; } canvas.getClipBounds(clipBounds); int normalizedOffset = offset; int layerWidth = bitmap.getWidth(); if (offset < -layerWidth) { offset += (int) (floor(abs(normalizedOffset) / (float) layerWidth) * layerWidth); } int left = offset; while (left < clipBounds.width()) { canvas.drawBitmap(bitmap, getBitmapLeft(layerWidth, left), 0, null); left += layerWidth; } if (isStarted) { offset -= speed; postInvalidateOnAnimation(); } } private float getBitmapLeft(int layerWidth, int left) { float bitmapLeft = left; if (speed < 0) { bitmapLeft = clipBounds.width() - layerWidth - left; } return bitmapLeft; } /** * Start the animation */ public void start() { if (!isStarted) { isStarted = true; postInvalidateOnAnimation(); } } /** * Stop the animation */ public void stop() { if (isStarted) { isStarted = false; invalidate(); } } }
以上就是直播系統原始碼,圖片一直滾動,迴圈滾動,豎向和橫向實現的相關程式碼, 更多內容歡迎關注之後的文章
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2843864/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 論移動裝置內容的橫向滾動和豎向滾動
- 線上直播系統原始碼,橫向無限迴圈滾動的單行彈幕效果原始碼
- 影片直播app原始碼,純css實現橫向滾動APP原始碼CSS
- JavaScript圖片橫向無縫滾動詳解JavaScript
- 縱向控制的橫向滾動
- 線上直播系統原始碼,迴圈滾動RecyclerView的實現原始碼View
- bootstrap table 橫向滾動條boot
- 直播軟體原始碼,橫向滾動 自定義底部指示器樣式原始碼
- jQuery內容橫向拖拽滾動jQuery
- 直播平臺原始碼,迴圈滾動RecyclerView的實現原始碼View
- js文字橫向無縫滾動程式碼例項JS
- 支援橫向、豎向無限滾動和自定義指示器的廣告條BannerView和淘寶頭條效果View
- 兩種方式實現橫向滾動條
- 一行程式碼實現滑鼠橫向滾動💪行程
- 直播系統原始碼,vue實現無縫滾動原始碼Vue
- 無縫迴圈滾動
- 三叉戟之橫向自定義滾動
- iOS Swift UICollectionView橫向分頁滾動,cell左右排版iOSSwiftUIView
- 直播原始碼,實現內容列表的豎向滑動原始碼
- 直播商城原始碼,vue 彈窗 慣性滾動 加速滾動原始碼Vue
- Unity-卡片迴圈滾動Unity
- 文字垂直迴圈滾動效果
- javascript無限迴圈滾動JavaScript
- 如何讓 fixed 定位的導航條可橫向滾動?
- 直播app系統原始碼,css優化滾動條樣式APP原始碼CSS優化
- web 移動端 橫向滾動的阻尼感很強,滑動不靈敏Web
- 線上直播系統原始碼,滾動式內容展示控制元件原始碼控制元件
- 直播系統原始碼,點選滾動的輪播圖自動跳轉到相應頁原始碼
- 頁面圖片自動滾動
- 資料視窗橫向滾動時用PB鎖定某列
- 直播系統app原始碼,垂直,水平無限迴圈滑動APP原始碼
- CSS實現迴圈無縫滾動CSS
- Java——圖片滾動顯示Java
- javascript實現圖片滾動JavaScript
- (轉)jquery圖片左右滾動jQuery
- JS圖片滾動(無縫、平滑、上下左右滾動)效果JS
- Windows10系統音量調節橫向怎麼改為豎向Windows
- 直播系統原始碼,雲朵左右移動迴圈動畫實現原始碼動畫