Android仿抖音我的页面,Android自定义videoview仿抖音界面
本文实例为大家分享了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
* 邮箱:[email protected]
* 说明:自定义宽高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界面
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">
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" />
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" />
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">
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家里几个垃圾了个两个垃圾" />
android:id="@+id/mVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false" />
4.drawable
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
5.主界面设置地址,注意,本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();
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持猪先飞。
Android仿抖音我的页面,Android自定义videoview仿抖音界面相关推荐
- Android之实现长按Webview页面文字自定义复制、全选、分享、搜索、翻译功能(支持多语言,博文也有Demo下载地址)
1 需求和效果爆照 浏览器app封装了Webview,然后实现实现长按Webview页面文字自定义复制.全选.分享.搜索.翻译功能(支持多语言),都在自己的浏览器app里面进行搜索和翻译,不跳到系统浏 ...
- 仿淘宝商品详情页面Android
[致谢]:qifengdeqingchen [博客地址]:http://blog.csdn.net/qifengdeqingchen/article/details/51659735 1.需求: 要实 ...
- android高仿微信下拉有页面,Android——(仿微信聊天界面布局实例)
今天看郭霖<第一行代码>书上写了一个聊天窗体的小例子,自己就练习学了一下.加上一些自己的理解整理了一下. 1.第一步首先是制作9.patch图片,这个在android sdk 目录下to ...
- android 点击item跳转页面,Android RecyclerView Item 点击事件,简单
在适配器中设置项的点击事件即可,如需跳转Activity,则需要intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_ ...
- android微信支付后返回第三方页面,微信支付后怎么返回指定界面 ios开发
满意答案 timerise 2015.09.07 采纳率:40% 等级:10 已帮助:671人 在以下两个方法中实现(AppDelegate) //弃用的返回 - (BOOL)applicati ...
- android抖音切换实现,【Android 进阶】仿抖音系列之视频预览和录制(五)
前言 大家好,在前几篇中,我们通过2种方式实现了仿抖音的翻页切换视频,仿抖音列表播放视频功能:这一篇,我们来说说视频的录制. 主流的视频录制,一般都采用的是FFmpeg 例如 腾讯短视频,由于FFmp ...
- android仿今日头条个人中心页面
android仿今日头条个人中心页面 效果图 实现步骤: 自定义ScrollView,添加一个反弹的动画 代码: package com.example.administrator.gerenzhon ...
- Android 抖音爱心动画,Android自定义View实现抖音飘动红心效果
本文实例为大家分享了Android自定义View实现抖音飘动红心效果的具体代码,供大家参考,具体内容如下 自定义View--抖音飘动红心 效果展示 动画效果 使用自定义view完成红心飘动效果 Vie ...
- 高仿简书Android,高仿简书个人中心页面
高仿简书个人中心页面 Demo下载地址: 先贴上效果图 1. 步骤 1.1 把APP的主题改为NoAction 1.2 引入Material Design 包 implementation 'com. ...
最新文章
- @程序员:Java平均工资再次上涨,光张年限不涨薪的我慌了!
- 敲山震虎?继MongoDB之后,AWS又对Elasticsearch下手了
- 点云数据格式 数据集笔记
- ug不能自动启动服务器,没有足够的权限启动系统服务解决方法
- 为什么程序员的社会地位不高?
- 海德堡大学 BMCV 组博士招生,生物医学图像分析领域​
- 如何用c语言调用c++做成的动态链接库
- Northwind数据库练习及参考答案
- 联想K31笔记本完全拆解,装不回去了。想做个电视机或者显示器
- 路演商业计划书PPT模板
- 每天一个命令:ps命令
- python中一切都是对象对吗_在 Python 中一切皆对象,它完全支持()
- 网络安全框架知多少?
- JAVA:使用华为云存储OBS处理文件
- linux test1
- 服务端Skynet(五)——如何搭建一个实例
- dotween 的学习1.DoTween.To()的了解
- 【Python】列表元素输入
- “0xc000007b无法正常启动”我的解决方案
- vue解决闪现遇到的问题
热门文章
- Form 表单提交 和 Ajax 表单提交 的一些区别
- MapReduce编程框架
- python 多线程和协程的区别
- 杨元原博士国密课堂 · 第一期 | 商用密码应用安全性评估:Part1. 密码算法概述
- win7电脑系统计算机中丢失v8.ll,系统回测问题 (文华财经WH8赢智V8.2)
- 如何做自媒体,这5大不同类型平台一定要了解
- centos7下配置tomcat环境变量
- 树莓派基于分类器的识别环保标志(五)
- css边框三角形 怎么用css样式写出三角形 css三角形怎么实现消息框
- 【玩机】华为,vivo系统,iqoo通过adb关闭系统升级更新