Piyano Uygulaması
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:onClick="button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="1"
android:textSize="25dp" />
<Button
android:id="@+id/button2"
android:onClick="button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="2"
android:textSize="25dp" />
<Button
android:id="@+id/button3"
android:onClick="button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="3"
android:textSize="25dp" />
<Button
android:id="@+id/button4"
android:onClick="button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="4"
android:textSize="25dp" />
<Button
android:id="@+id/button5"
android:onClick="button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="5"
android:textSize="25dp" />
<Button
android:id="@+id/button6"
android:onClick="button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="6"
android:textSize="25dp" />
<Button
android:id="@+id/button7"
android:onClick="button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="7"
android:textSize="25dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:onClick="button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="1"
android:textSize="25dp" />
<Button
android:id="@+id/button2"
android:onClick="button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="2"
android:textSize="25dp" />
<Button
android:id="@+id/button3"
android:onClick="button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="3"
android:textSize="25dp" />
<Button
android:id="@+id/button4"
android:onClick="button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="4"
android:textSize="25dp" />
<Button
android:id="@+id/button5"
android:onClick="button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="5"
android:textSize="25dp" />
<Button
android:id="@+id/button6"
android:onClick="button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="6"
android:textSize="25dp" />
<Button
android:id="@+id/button7"
android:onClick="button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:padding="20dp"
android:text="7"
android:textSize="25dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
ActivityMain.java
package com.example.a91butonses;
//import androidx.appcompat.app.AppCompatActivity;
import android.media.SoundPool;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private SoundPool soundPool;
private Integer integerSoundIDa;
private Integer integerSoundIDb;
private Integer integerSoundIDc;
private Integer integerSoundIDd;
private Integer integerSoundIDe;
private Integer integerSoundIDf;
private Integer integerSoundIDg;
private float floatSpeed = 1.0f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SoundPool.Builder builder = new SoundPool.Builder();
soundPool = builder.build();
integerSoundIDa = soundPool.load(this, R.raw.a3, 1);
integerSoundIDb = soundPool.load(this, R.raw.b3, 1);
integerSoundIDc = soundPool.load(this, R.raw.c3, 1);
integerSoundIDd = soundPool.load(this, R.raw.d3, 1);
integerSoundIDe = soundPool.load(this, R.raw.e3, 1);
integerSoundIDf = soundPool.load(this, R.raw.f3, 1);
integerSoundIDg = soundPool.load(this, R.raw.g3, 1);
}
public void button1(View view){
soundPool.play(integerSoundIDa, 1, 1, 1, 0, floatSpeed);
}
public void button2(View view){
soundPool.play(integerSoundIDb, 1, 1, 1, 0, floatSpeed);
}
public void button3(View view){
soundPool.play(integerSoundIDc, 1, 1, 1, 0, floatSpeed);
}
public void button4(View view){
soundPool.play(integerSoundIDd, 1, 1, 1, 0, floatSpeed);
}
public void button5(View view){
soundPool.play(integerSoundIDe, 1, 1, 1, 0, floatSpeed);
}
public void button6(View view){
soundPool.play(integerSoundIDf, 1, 1, 1, 0, floatSpeed);
}
public void button7(View view){
soundPool.play(integerSoundIDg, 1, 1, 1, 0, floatSpeed);
}
}
//import androidx.appcompat.app.AppCompatActivity;
import android.media.SoundPool;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private SoundPool soundPool;
private Integer integerSoundIDa;
private Integer integerSoundIDb;
private Integer integerSoundIDc;
private Integer integerSoundIDd;
private Integer integerSoundIDe;
private Integer integerSoundIDf;
private Integer integerSoundIDg;
private float floatSpeed = 1.0f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SoundPool.Builder builder = new SoundPool.Builder();
soundPool = builder.build();
integerSoundIDa = soundPool.load(this, R.raw.a3, 1);
integerSoundIDb = soundPool.load(this, R.raw.b3, 1);
integerSoundIDc = soundPool.load(this, R.raw.c3, 1);
integerSoundIDd = soundPool.load(this, R.raw.d3, 1);
integerSoundIDe = soundPool.load(this, R.raw.e3, 1);
integerSoundIDf = soundPool.load(this, R.raw.f3, 1);
integerSoundIDg = soundPool.load(this, R.raw.g3, 1);
}
public void button1(View view){
soundPool.play(integerSoundIDa, 1, 1, 1, 0, floatSpeed);
}
public void button2(View view){
soundPool.play(integerSoundIDb, 1, 1, 1, 0, floatSpeed);
}
public void button3(View view){
soundPool.play(integerSoundIDc, 1, 1, 1, 0, floatSpeed);
}
public void button4(View view){
soundPool.play(integerSoundIDd, 1, 1, 1, 0, floatSpeed);
}
public void button5(View view){
soundPool.play(integerSoundIDe, 1, 1, 1, 0, floatSpeed);
}
public void button6(View view){
soundPool.play(integerSoundIDf, 1, 1, 1, 0, floatSpeed);
}
public void button7(View view){
soundPool.play(integerSoundIDg, 1, 1, 1, 0, floatSpeed);
}
}

Yorumunuzu Ekleyin