Android用VideoView实现MP4作为页面背景(仿QQ登录页面效果)
来源:互联网 发布:gopro windows 编辑:程序博客网 时间:2024/06/05 13:32
类似Tumblr, Spotify, Keep等应用在登录界面都有要采用了背景是动画的效果。
1、布局文件:activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/home_container" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.huan.percy.backgroundvideotest.FullScreenVideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentBottom="true" android:layout_alignParentTop="true" android:layout_gravity="center" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:gravity="center" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:orientation="vertical"> <EditText android:layout_width="match_parent" android:layout_height="50dp" android:hint="手机/邮箱" android:textColor="#fff" android:textColorHint="#fff" android:background="@null" android:textSize="20sp" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/fls" android:scaleType="fitXY"/> <EditText android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="10dp" android:hint="密码" android:textColorHint="#fff" android:textColor="#fff" android:background="@null" android:textSize="20sp" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/fls" android:scaleType="fitXY"/> <Button android:id="@+id/login" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@mipmap/nhl" android:layout_marginTop="30dp" android:text="登 录" android:textColor="#fff" android:textSize="25sp" /> </LinearLayout></RelativeLayout>2、在raw文件夹中添加播放的MP4资源
3、自定义VideoView,使得播放视频填充屏幕
/** * Created by ZhuMing on 2017/7/12. * 自定义 填充屏幕的VideoView */public class FullScreenVideoView extends VideoView { public FullScreenVideoView(Context context) { super(context); } public FullScreenVideoView(Context context, AttributeSet attrs) { super(context, attrs); } public FullScreenVideoView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); int width = wm.getDefaultDisplay().getWidth(); int height = wm.getDefaultDisplay().getHeight(); setMeasuredDimension(width, height); }}
4、在需要加载动态背景的Activity的OnCreate()方法中加入相关控制代码,实现自动循环播放
public class MainActivity extends AppCompatActivity { private MediaPlayer mp = null; private FullScreenVideoView myVideoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); final String videoPath = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.welcome_video).toString(); myVideoView.setVideoPath(videoPath); myVideoView.start(); myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.start(); mp.setLooping(true); } }); myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { myVideoView.setVideoPath(videoPath); myVideoView.start(); } }); } private void initView() { myVideoView = (FullScreenVideoView) findViewById(R.id.videoView); }}
阅读全文
0 0
- Android用VideoView实现MP4作为页面背景(仿QQ登录页面效果)
- Android 仿QQ动态背景登录,Android用视频做背景的轻松实现
- Android即时通讯--仿QQ即时聊天:(二)闪屏页及登录页面的实现
- Android 仿QQ动态背景登录
- android 用sharepreferences实现仿QQ登录多账号的保存的效果
- 仿Android QQ实现的QQ顶栏椭圆透明背景移动效果
- Android仿网易云音乐播放页面 背景虚化碟片效果
- 仿TestCpp实现Layout页面切换效果
- React-Native开发(三)---仿QQ登录页面
- HTML+CSS实现动态背景登录页面
- android仿IOS页面回弹效果
- android仿ios页面跳转效果
- android仿QQ列表的效果实现
- Android实现仿qq侧边栏效果
- Android实现仿qq侧边栏效果
- 页面背景闪烁效果
- 模拟QQ登录页面
- Android实现一个登录页面
- 集合各实现类的底层实现原理
- jfinal下部署maven项目遇到的问题及解决方法
- 树中第一个公共祖先结点----解法
- 单元测试Qunit
- WIN7系统下U盘安装Ubuntu双系统
- Android用VideoView实现MP4作为页面背景(仿QQ登录页面效果)
- 关于Linearlayout里weight与子布局的wrap content
- php模拟长连接
- VS2010的编码经验
- tomcat大量time wait问题
- Spring Data JPA入门
- #bzoj1846
- 破解防拷贝脚本
- C 预处理器和C库