Android实现登录背景动画效果
登录QQ的时候,我们会看到在登录界面的背景不是静态的,而是一段动画效果,刚开始觉得蛮好奇的,现在我们也来实现一下这种效果,实现起来还是挺简单的。
效果图:

实现步骤:
1、自定义CustomVideoView类继承VideoView
2、实现xml布局文件
3、将视频文件放入raw目录
4、代码实现动画效果
实现过程:
1、自定义CustomVideoView类继承VideoView
package com.example.viewdemo;import android.content.Context;import android.media.MediaPlayer;import android.util.AttributeSet;import android.view.KeyEvent;import android.widget.VideoView;public class CustomVideoView extends VideoView {public CustomVideoView(Context context) {super(context);}public CustomVideoView(Context context, AttributeSet attrs) {super(context, attrs);}public CustomVideoView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {//我们重新计算高度int width = getDefaultSize(0, widthMeasureSpec);int height = getDefaultSize(0, heightMeasureSpec);setMeasuredDimension(width, height);}public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {super.setOnPreparedListener(l);}public boolean onKeyDown(int keyCode, KeyEvent event) {return super.onKeyDown(keyCode, event);}}
2、实现xml布局文件
<com.example.viewdemo.CustomVideoViewandroid:id="@+id/videoview"android:layout_width="match_parent"android:layout_height="match_parent" />
3、将视频文件放入raw目录

4、代码实现动画效果
//找VideoView控件customVideoView = (CustomVideoView) findViewById(R.id.videoview);//加载视频文件customVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sport));//播放customVideoView.start();//循环播放customVideoView.setOnCompletionListener(newMediaPlayer.OnCompletionListener() {publicvoid onCompletion (MediaPlayer mediaPlayer){customVideoView.start();}});
需要源码的童鞋在公众号【龙旋】对话框回复关键字【背景动画】即可获取哦.
到这里就结束啦.
评论
