模仿手机QQ以视频流背景的登录界面
来源:互联网 发布:业务本软件 编辑:程序博客网 时间:2024/04/30 06:52
1. 思路:很简单,VideoView播放视频。
布局方式如下:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:id="@+id/activity_video_view_background" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.aaron.videoviewbackground.VideoViewBackground"> <com.example.aaron.videoviewbackground.CommonVideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerInParent="true" android:layout_marginTop="50dp" android:text="手机QQ" android:textSize="50dp" android:textColor="@color/color1" android:gravity="center"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="40dp"> <TextView android:layout_width="130dp" android:layout_height="30dp" android:layout_alignParentLeft="true" android:gravity="center" android:textSize="20dp" android:textColor="@color/color1" android:text="@string/login" android:layout_marginLeft="30dp" android:background="@color/color2"/> <TextView android:layout_width="130dp" android:layout_height="30dp" android:gravity="center" android:layout_alignParentRight="true" android:layout_marginRight="30dp" android:textSize="20dp" android:text="@string/register" android:textColor="@color/color1" android:background="@color/color2"/> </RelativeLayout></RelativeLayout>
2. 这里自定义了一个CommonVideoView,适合一些小屏幕手机,需要测量下它的宽高。
/** * Created by Aaron on 2017/7/23. */public class CommonVideoView extends VideoView{// region constructor/** * the constructor */public CommonVideoView(Context context){super(context);}public CommonVideoView(Context context, AttributeSet attrs){super(context, attrs);}public CommonVideoView(Context context, AttributeSet attrs, int defStyleAttr){super(context, attrs, defStyleAttr);} // endregion// region public@Overridepublic void setOnPreparedListener(MediaPlayer.OnPreparedListener l){super.setOnPreparedListener(l);}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event){return super.onKeyDown(keyCode, event);}// endregion// region protected@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){int width = getDefaultSize(0, widthMeasureSpec);int height = getDefaultSize(0, heightMeasureSpec);setMeasuredDimension(width, height);}// endregion}
3.核心代码也很简单,这里注意下设置全屏模式,还有加入视频播放权限。
public class VideoViewBackground extends AppCompatActivity{private CommonVideoView mVideoView;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_video_view_background);mVideoView = (CommonVideoView) this.findViewById(R.id.videoView);playVideoView();}private void playVideoView(){mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video));//播放mVideoView.start();//循环播放mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {@Overridepublic void onCompletion(MediaPlayer mediaPlayer) {mVideoView.start();}});}//返回重启加载@Overrideprotected void onRestart() {playVideoView();super.onRestart();}//防止锁屏或者切出的时候,音乐在播放@Overrideprotected void onStop() {mVideoView.stopPlayback();super.onStop();}}
在资源文件下放入要播放的视频文件Video,这里的Video我是选用手机QQ里面的(反编译得到的,直接可以拿到),OK,大致实现代码就这样,很简单。
可以看下如上效果图:
阅读全文
1 0
- 模仿手机QQ以视频流背景的登录界面
- 模仿QQ背景为视频的登录页
- 视频做背景,模仿QQ,小红书等登录时的背景视频
- swing 模仿QQ登录界面
- 简单模仿qq登录界面
- 原创安卓手机QQ7.0登录界面动态背景视频实现方案
- Android 仿QQ动态背景登录,Android用视频做背景的轻松实现
- 模仿概念版QQ登录界面(超炫)
- Android 模仿QQ登录界面解决软键盘遮挡问题
- 我模仿的QQ界面贴图
- 模仿QQ运动item的界面
- 模仿QQ界面
- 模仿登录界面
- 模仿QQ截图时的灰色透明背景
- 手机登录界面的实现
- 用Fragment模仿QQ界面
- Java聊天室,界面模仿QQ
- 以图片为背景 的登陆界面
- 利用ffmpeg和opencv进行视频的解码播放
- STL之Vector实现原理
- android6.0手机蓝牙与ble蓝牙模块通信
- 8月1日训练日记
- JS基础学习应用之ajax.js函数的封装
- 模仿手机QQ以视频流背景的登录界面
- Spring+Mybatis框架的简单搭建
- 3. mlab基础
- USACO 2017 US OPEN PLATINUM题目翻译(未完)
- spring框架基础学习
- 欢迎使用CSDN-markdown编辑器
- Spring:Looks like the Spring listener was not configured for your web app!
- 程序级的AOP到底好不好?
- Activity启动模式,任务栈以及taskAffinity属性