本文实例为大家分享了Android自定义videoview仿抖音界面的具体代码,供大家参考,具体内容如下
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="测试测试数据哈哈哈哈\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.主界面设置地址,注意,本demo使用的是本地的视频文件,文件存储再../res/raw文件夹里面,请自行获取
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。