Android--简单电子木鱼开发详解

8 篇文章 0 订阅
2 篇文章 0 订阅

PS:素材和整个文件我都会放在最后请耐心看完~

简单看下效果:

页面布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/img_show"
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:src="@mipmap/dzmy" />


    <TextView
        android:id="@+id/tc_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="000"
        android:layout_weight="1"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/white"
        android:textSize="60sp" />


</LinearLayout>

 主要实现代码:

package com.example.muyu2;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView touchTime;
    int i = 0;
    private ImageView imgShow;
    private Button bt;
    private Animation animation = null;
    private TextView mBtnmusic;
    private SoundPool soundPool;
    private int soundID;
    private MediaPlayer music;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        handler.sendEmptyMessage(0);
        touchTime = (TextView) findViewById(R.id.tc_time);
        intview();

    }

    private void intview() {
        imgShow = findViewById(R.id.img_show);
        animation = AnimationUtils.loadAnimation(this, R.anim.muyu);
        imgShow.startAnimation(animation);
        animation.setFillAfter(true);

        imgShow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                intview();
                PlayMusic(R.raw.split);//第二种方式
                i++;
/*                MyThread1 mt = new MyThread1();
                Thread mt11 = new Thread(mt);
                mt11.start();*/

            }
        });
    }


/*    private class MyThread1 implements Runnable {
        @Override
        public void run() {
        }
    }*/
    @SuppressLint("NewApi")
    private void initSound() {
        soundPool = new SoundPool.Builder().build();
        soundID = soundPool.load(this, R.raw.split, 1);
    }

    private void PlayMusic(int MusicId) {
        music = MediaPlayer.create(this, MusicId);
        music.start();
    }

    private void playsound() {
        soundPool.play(
                soundID,
                0.1f,      //左耳道音量【0~1】
                0.5f,      //右耳道音量【0~1】
                0,         //播放优先级【0表示最低优先级】
                0,         //循环模式【0表示循环一次,-1表示一直循环,其他表示数字+1表示当前数字对应的循环次数】
                1          //播放速度【1是正常,范围从0~2】
        );
    }
    Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
                touchTime.setText(i + "");
            if (i != i - 1) {
                handler.sendEmptyMessageDelayed(0, 500);
            }
        }
    };
}

这里需要注意的一个点就是修改界面UI的线程得写在主线程上

 这里我们需要自己创建动画文件夹和音频文件夹来存放素材:

这里我们选择anim文件夹存放动画xml,raw文件夹存放音频;

muyu动画代码:

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.95"
    android:toYScale="0.95" />

 把前面的代码copy完差不多就能实现功能的,素材下面自取,免费,觉得有帮助麻烦点个赞,谢谢!

 

 迅雷云盘:链接:https://pan.xunlei.com/s/VNF9LOFpmGf6vsfpZR5TEQTQA1?pwd=a2st#
提取码:a2st

百度云盘:链接: https://pan.baidu.com/s/1d407_ZF6GldlIJ1vecJmIA?pwd=xyxf 提取码: xyxf

CSDN:Android,电子木鱼,1024传-Android文档类资源-CSDN下载免费,可以的话帮我点赞,谢谢更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/qq_55985667/86815273

  • 10
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值