最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義videoview仿抖音界面

 更新時間:2021年05月09日 08:49:23   作者:勘察加熊人  
這篇文章主要為大家詳細(xì)介紹了Android自定義videoview仿抖音界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

1.效果圖

和抖音的界面效果一模一樣,而且可以自定義,需要什么頁面,請自己定義

2.自定義videoview

package com.example.myapplication20;
 
 
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
 
 
/**
 * 作者:created by Jarchie
 * 時間:2020/12/7 15:05:57
 * 郵箱:jarchie520@gmail.com
 * 說明:自定義寬高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:id="@+id/mRootView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <ImageView
        android:id="@+id/mThumb"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="false"
        android:focusable="false"
        android:scaleType="centerCrop"
        android:visibility="visible" />
 
    <ImageView
        android:id="@+id/mPlay"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:alpha="0"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/play_arrow" />
 
 
    <LinearLayout
        android: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:id="@+id/mTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lineSpacingExtra="5dp"
            android:textColor="@android:color/white"
            android:textSize="16sp"
            tools:text="測試測試數(shù)據(jù)哈哈哈哈\n家里幾個垃圾了個兩個垃圾" />
 
 
    </LinearLayout>
 
    <com.example.myapplication20.CusVideoView
        android:id="@+id/mVideoView"
        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:height="24dp"
    android:viewportHeight="24.0" android:viewportWidth="24.0"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#99ffffff" android:pathData="M8,5v14l11,-7z"/>
</vector>

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

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一起來跳支舞吧");
    }
 
 
    @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();
    }
 
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 老生常談onTouch和onTouchEvent(必看篇)

    老生常談onTouch和onTouchEvent(必看篇)

    下面小編就為大家?guī)硪黄仙U刼nTouch和onTouchEvent(必看篇)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • ImageView 實現(xiàn)Android colorPikcer 選擇器的示例代碼

    ImageView 實現(xiàn)Android colorPikcer 選擇器的示例代碼

    本篇文章主要介紹了ImageView 實現(xiàn)Android colorPikcer 選擇器的示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-10-10
  • Android View 事件分發(fā)機制詳解

    Android View 事件分發(fā)機制詳解

    本文主要介紹Android View 事件分發(fā)機制,這里整理了相關(guān)資料并詳細(xì)介紹了view分發(fā)機制的知識及簡單示例代碼,有興趣的小伙伴可以參考下
    2016-08-08
  • Android5.0多種側(cè)滑欄效果實例代碼

    Android5.0多種側(cè)滑欄效果實例代碼

    這篇文章主要介紹了Android5.0多種側(cè)滑欄效果實例代碼的相關(guān)資料,本文圖文并茂介紹的非常詳細(xì),需要的朋友可以參考下
    2016-09-09
  • Android中使用TextToSpeech的方法

    Android中使用TextToSpeech的方法

    這篇文章主要介紹了Android中TextToSpeech的使用,通過初始化語音,這是一個異步操作,初始化完成后調(diào)用oninitListener,具體實例代碼跟隨小編一起看看吧
    2021-09-09
  • android基于dialog實現(xiàn)等待加載框示例

    android基于dialog實現(xiàn)等待加載框示例

    本篇文章主要介紹了android基于dialog實現(xiàn)等待加載框示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • Android中獲取IMEI碼的方法

    Android中獲取IMEI碼的方法

    本篇文章是對在Android中獲取IMEI碼的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • android自定義窗口標(biāo)題示例分享

    android自定義窗口標(biāo)題示例分享

    這篇文章主要介紹了android自定義窗口標(biāo)題示例,需要的朋友可以參考下
    2014-03-03
  • 解決webview 第二次調(diào)用loadUrl頁面不刷新的問題

    解決webview 第二次調(diào)用loadUrl頁面不刷新的問題

    這篇文章主要介紹了解決webview 第二次調(diào)用loadUrl頁面不刷新的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Flutter集成到已有iOS工程的方法步驟

    Flutter集成到已有iOS工程的方法步驟

    這篇文章主要介紹了Flutter集成到已有iOS工程的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03

最新評論

鄄城县| 磐石市| 宣威市| 如皋市| 泗洪县| 张掖市| 互助| 尖扎县| 历史| 化州市| 辽源市| 白银市| 扶沟县| 柯坪县| 仪征市| 秭归县| 洛川县| 苏尼特左旗| 佛学| 寻乌县| 奉新县| 杭锦旗| 怀远县| 陆良县| 吴忠市| 福海县| 大理市| 察哈| 碌曲县| 富裕县| 格尔木市| 邛崃市| 夏津县| 印江| 乌兰县| 秭归县| 潞城市| 博白县| 光泽县| 庆阳市| 个旧市|