亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Android自定義videoview仿抖音界面

瀏覽:105日期:2022-06-04 14:16:44

本文實(shí)例為大家分享了Android自定義videoview仿抖音界面的具體代碼,供大家參考,具體內(nèi)容如下

1.效果圖

和抖音的界面效果一模一樣,而且可以自定義,需要什么頁(yè)面,請(qǐng)自己定義

2.自定義videoview

package com.example.myapplication20; import android.content.Context;import android.util.AttributeSet;import android.widget.VideoView; /** * 作者:created by Jarchie * 時(shí)間:2020/12/7 15:05:57 * 郵箱:jarchie520@gmail.com * 說(shuō)明:自定義寬高VideoView */public class CusVideoView extends VideoView { public CusVideoView(Context context) {super(context); } public CusVideoView(Context context, AttributeSet attrs) {super(context, attrs); } public CusVideoView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);int width = getDefaultSize(getWidth(), widthMeasureSpec);int height = getDefaultSize(getHeight(), heightMeasureSpec);setMeasuredDimension(width, height); }}

3.xml界面

<?xml version='1.0' encoding='utf-8'?><RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android: android:layout_width='match_parent' android:layout_height='match_parent'> <ImageViewandroid: android:layout_width='match_parent'android:layout_height='match_parent'android:clickable='false'android:focusable='false'android:scaleType='centerCrop'android:visibility='visible' /> <ImageViewandroid: android:layout_width='100dp'android:layout_height='100dp'android:layout_centerInParent='true'android:alpha='0'android:clickable='true'android:focusable='true'android:src='http://www.aoyou183.cn/bcjs/@drawable/play_arrow' /> <LinearLayoutandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_alignParentBottom='true'android:layout_marginLeft='10dp'android:layout_marginBottom='60dp'android:orientation='vertical'> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:lineSpacingExtra='5dp' android:textColor='@android:color/white' android:textSize='16sp' tools:text='測(cè)試測(cè)試數(shù)據(jù)哈哈哈哈n家里幾個(gè)垃圾了個(gè)兩個(gè)垃圾' /> </LinearLayout> <com.example.myapplication20.CusVideoViewandroid: android:layout_width='match_parent'android:layout_height='match_parent'android:clickable='false'android:focusable='false' /></RelativeLayout>

4.drawable

<vector android:alpha='0.61' android: android:viewportHeight='24.0' android:viewportWidth='24.0' android: xmlns:android='http://schemas.android.com/apk/res/android'> <path android:fillColor='#99ffffff' android:pathData='M8,5v14l11,-7z'/></vector>

5.主界面設(shè)置地址,注意,本demo使用的是本地的視頻文件,文件存儲(chǔ)再../res/raw文件夾里面,請(qǐng)自行獲取

package com.example.myapplication20; import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity; import android.media.MediaPlayer;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.ImageView;import android.widget.TextView; import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity; /** * 作者:JArchie * 源碼參考地址:https://github.com/JArchie/TiktokDemo */ public class MainActivity extends AppCompatActivity { CusVideoView mVideoView; private int[] videos = {R.raw.v1, R.raw.v2, R.raw.qi}; TextView mTitle; @Override protected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main); mVideoView = findViewById(R.id.mVideoView);mTitle = findViewById(R.id.mTitle); String url = 'android.resource://' + getPackageName() + '/' + videos[1];Log.e('TAG', 'video_onCreate: ' + url); mVideoView.setVideoURI(Uri.parse(url));mTitle.setText('@王燕n一起來(lái)跳支舞吧'); } @Override protected void onStart() {super.onStart();playVideo(); } @Override protected void onDestroy() {super.onDestroy();releaseVideo(); } //播放 private void playVideo() { Log.e('TAG', 'play_video'); // View itemView = mRecycler.getChildAt(0);final CusVideoView mVideoView = findViewById(R.id.mVideoView);final ImageView mPlay = findViewById(R.id.mPlay);final ImageView mThumb = findViewById(R.id.mThumb);final MediaPlayer[] mMediaPlayer = new MediaPlayer[1];mVideoView.start(); mVideoView.setOnInfoListener(new MediaPlayer.OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) {mMediaPlayer[0] = mp;mp.setLooping(true);mThumb.animate().alpha(0).setDuration(200).start();return false; }}); //暫停控制mPlay.setOnClickListener(new View.OnClickListener() { boolean isPlaying = true; @Override public void onClick(View v) {if (mVideoView.isPlaying()) { mPlay.animate().alpha(1f).start(); mVideoView.pause(); isPlaying = false;} else { mPlay.animate().alpha(0f).start(); mVideoView.start(); isPlaying = true;} }}); } //釋放 private void releaseVideo() { Log.e('TAG', 'releaseVideo_video'); // View itemView = mRecycler.getChildAt(index);final CusVideoView mVideoView = findViewById(R.id.mVideoView);final ImageView mThumb = findViewById(R.id.mThumb);final ImageView mPlay = findViewById(R.id.mPlay);mVideoView.stopPlayback();mThumb.animate().alpha(1).start();mPlay.animate().alpha(0f).start(); } }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: 抖音
相關(guān)文章:
主站蜘蛛池模板: 性视频播放免费视频 | 国产高清不卡码一区二区三区 | 91高清免费国产自产拍2021 | 国产91精品一区二区麻豆网站 | 色婷婷综合激情视频免费看 | 精品福利一区二区三区免费视频 | 亚洲国产精品综合久久网络 | 尤物视频在线免费 | 色婷婷精品视频 | 久久99精品一级毛片 | 国产女主播91 | 欧美日韩亚洲国产一区二区三区 | 国内精品综合九九久久精品 | 精品五夜婷香蕉国产线看观看 | 久久免费99精品久久久久久 | 国产在线观看高清不卡 | 成人性生交大片免费看软件 | 久久机热一这里只精品 | 26uuu老色哥 26uuu欧美视频在线观看 | 草草视频在线免费观看 | 国产乱码在线精品可播放 | 国产精品午夜寂寞视频 | 久久国产精品久久久久久 | 欧美在线观看免费一区视频 | freesexvideo性大全 | 日韩中文字幕久久精品 | 亚洲国产精品美女 | 欧美成人中文字幕 | 亚洲综合色区图片区 | 免费国产成人手机在线观看 | 黄色观看视频 | 国产露脸对白刺激3p在线 | 色秀影院| 精品国产人成亚洲区 | 动漫chinesehdxxxx| 国产精品国产三级国产专不∫ | 日韩字幕| 国产精品网红 | 国产精品九九 | 日本老年人精品久久中文字幕 | 哪有黄色网址 |