android 仿仿QQ动态背景、视频背景的示例代码动态背景、视频背景的示例代码
本篇文章主要介绍了android 仿QQ动态背景、视频背景的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
本文介绍了android 仿QQ动态背景、视频背景的示例代码,分享给大家,具体如下:
效果如下:
如上图类似效果图:
1, 自定义视频类 继承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);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//我们重新计算高度
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
}
@Override
public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {
super.setOnPreparedListener(l);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
}
}
MainActivity 中:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private CustomVideoView videoview;
private Button btn_enter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);