日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

D1Android-钢琴模拟实现

發布時間:2024/3/24 Android 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 D1Android-钢琴模拟实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、效果圖:

二、操作步驟:

java功能:①MainActivity.java

package cn.itcast.e24_pianoplayer_application;import android.app.Activity; import android.media.AudioManager; import android.media.SoundPool; import android.os.Bundle;import android.view.View; import android.widget.ImageView;import java.util.HashMap;public class MainActivity extends Activity implements View.OnClickListener {private SoundPool soundpool;private HashMap<Integer,Integer> map = new HashMap<>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//初始化界面控件,并為控件添加點擊事件的監聽器ImageView iv_do = findViewById(R.id.iv_do);ImageView iv_re = findViewById(R.id.iv_re);ImageView iv_mi = findViewById(R.id.iv_mi);ImageView iv_fa = findViewById(R.id.iv_fa);ImageView iv_so = findViewById(R.id.iv_so);ImageView iv_la = findViewById(R.id.iv_la);ImageView iv_si = findViewById(R.id.iv_si);iv_do.setOnClickListener(this);iv_re.setOnClickListener(this);iv_mi.setOnClickListener(this);iv_fa.setOnClickListener(this);iv_so.setOnClickListener(this);iv_la.setOnClickListener(this);iv_si.setOnClickListener(this);initSoundPool();//初始化SoundPool}private void initSoundPool() {if(soundpool == null){//創建SoundPool對象soundpool = new SoundPool(7, AudioManager.STREAM_SYSTEM, 0);}//加載音頻文件,并將文件存儲到HashMap集合中map.put(R.id.iv_do,soundpool.load(this,R.raw.music_do,1));map.put(R.id.iv_re,soundpool.load(this,R.raw.music_re,1));map.put(R.id.iv_mi,soundpool.load(this,R.raw.music_mi,1));map.put(R.id.iv_fa,soundpool.load(this,R.raw.music_fa,1));map.put(R.id.iv_so,soundpool.load(this,R.raw.music_so,1));map.put(R.id.iv_la,soundpool.load(this,R.raw.music_la,1));map.put(R.id.iv_si,soundpool.load(this,R.raw.music_si,1));}@Overridepublic void onClick(View v) {play(v.getId());}private void play(int i){soundpool.play(map.get(i),1.0f,1.0f,0,0,1.0f); //播放音頻}@Overrideprotected void onDestroy() {super.onDestroy();if (soundpool != null) {soundpool.autoPause(); //暫停播放音頻soundpool.release(); //釋放Soundpool對象占用的資源soundpool = null;}} }

?背景布局:②ic_launcher_background.xml

<?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android"android:width="108dp"android:height="108dp"android:viewportWidth="108"android:viewportHeight="108"><pathandroid:fillColor="#008577"android:pathData="M0,0h108v108h-108z" /><pathandroid:fillColor="#00000000"android:pathData="M9,0L9,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,0L19,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M29,0L29,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M39,0L39,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M49,0L49,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M59,0L59,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M69,0L69,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M79,0L79,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M89,0L89,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M99,0L99,108"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,9L108,9"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,19L108,19"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,29L108,29"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,39L108,39"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,49L108,49"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,59L108,59"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,69L108,69"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,79L108,79"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,89L108,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M0,99L108,99"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,29L89,29"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,39L89,39"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,49L89,49"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,59L89,59"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,69L89,69"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M19,79L89,79"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M29,19L29,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M39,19L39,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M49,19L49,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M59,19L59,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M69,19L69,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /><pathandroid:fillColor="#00000000"android:pathData="M79,19L79,89"android:strokeWidth="0.8"android:strokeColor="#33FFFFFF" /> </vector>

各個音符(1/7):③icon_do_selector.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/icon_do" android:state_pressed="false"/><item android:drawable="@drawable/icon_do_pressed"android:state_pressed="true"/> </selector>

三、代碼講解:待填……

四、代碼資源:

Android鋼琴模擬器-Android文檔類資源-CSDN文庫?

總結

以上是生活随笔為你收集整理的D1Android-钢琴模拟实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。