-
-
Save codeforfun-jp/d92c26e5d90d478cd8dea5ba25207a38 to your computer and use it in GitHub Desktop.
CTB 3-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.codeforfun.catchtheball; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
private TextView scoreLabel; | |
private TextView startLabel; | |
private ImageView box; | |
private ImageView orange; | |
private ImageView pink; | |
private ImageView black; | |
// 位置 | |
private float boxY; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
scoreLabel = findViewById(R.id.scoreLabel); | |
startLabel = findViewById(R.id.startLabel); | |
box = findViewById(R.id.box); | |
orange = findViewById(R.id.orange); | |
pink = findViewById(R.id.pink); | |
black = findViewById(R.id.black); | |
orange.setX(-80.0f); | |
orange.setY(-80.0f); | |
pink.setX(-80.0f); | |
pink.setY(-80.0f); | |
black.setX(-80.0f); | |
black.setY(-80.0f); | |
startLabel.setVisibility(View.INVISIBLE); | |
boxY = 500.0f; | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
if (event.getAction() == MotionEvent.ACTION_DOWN) { | |
boxY -= 20; | |
} | |
box.setY(boxY); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment