最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android?studio實現(xiàn)動態(tài)背景頁面

 更新時間:2022年04月23日 10:50:59   作者:小嘉圓子  
這篇文章主要為大家詳細(xì)介紹了Android?studio實現(xiàn)動態(tài)背景頁面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android studio實現(xiàn)動態(tài)背景頁面的具體代碼,供大家參考,具體內(nèi)容如下

第一步:

在res目錄下創(chuàng)建raw文件夾,并把想要導(dǎo)入的視頻放在里面

可以用格式工廠先把視頻格式化,以免視頻內(nèi)存過大無法運行。

第二步:配置頁面布局xml文件

1.在activity_main.xml文件里加入以下代碼:

//放在大布局框架里
android:fitsSystemWindows="true"
//放在布局框架內(nèi)
? ?<com.example.lovestoryapp.CustomVideoView
? ? ? ? android:id="@+id/videoview"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent" />

2.在layout文件夾里創(chuàng)建videoview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent">
? ? <VideoView
? ? ? ? android:id="@+id/videoview"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:layout_marginBottom="-150dp"
? ? ? ? android:layout_alignParentLeft="true"
? ? ? ? android:layout_alignParentRight="true"
? ? ? ? android:layout_alignParentBottom="true"
? ? ? ? android:layout_alignParentTop="true" />
?
</RelativeLayout>

第三步:配置java文件

1.創(chuàng)建java文件 CustomVideoView.java

package com.example.lovestoryapp;
?
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);
? ? }
?
? ? @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);
? ? }
}

2.在MainActivity.java的Activity方法中加入以下代碼

?//找VideoView控件
? ? ? ? customVideoView = (CustomVideoView)findViewById(R.id.videoview);
? ? ? ? //加載視頻文件
? ? ? ? customVideoView.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.shipin1));
? ? ? ? //播放
? ? ? ? customVideoView.start();
? ? ? ? //循環(huán)播放
? ? ? ? customVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onCompletion(MediaPlayer mediaPlayer) {
? ? ? ? ? ? ? ? customVideoView.start();
? ? ? ? ? ? }
? ? ? ? });
?
? ? }

第四步:運行至模擬器

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

无极县| 泗洪县| 洱源县| 梧州市| 晋江市| 永丰县| 凤阳县| 虞城县| 衢州市| 密山市| 宽甸| 体育| 晋宁县| 屏山县| 永丰县| 三江| 靖边县| 揭阳市| 阜南县| 华阴市| 双城市| 水富县| 徐闻县| 长岛县| 墨玉县| 上饶县| 刚察县| 高要市| 城步| 上饶县| 会东县| 崇文区| 宝应县| 桃源县| 德钦县| 海淀区| 福鼎市| 菏泽市| 玛沁县| 丁青县| 理塘县|