質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Q&A

1回答

1614閲覧

AndroidをEcliplseで書いているのですが動く玉をクリックしたら画像に変えたい

RoimyZomsa

総合スコア15

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

0グッド

0クリップ

投稿2017/03/08 09:57

これで動く玉がクリックされたら画像に変更するコードに変えたいのですが

java

1package surfaceviewsample0306; 2 3import java.util.ArrayList; 4 5import android.support.v7.app.ActionBarActivity; 6import android.annotation.SuppressLint; 7import android.graphics.Bitmap; 8import android.graphics.BitmapFactory; 9import android.graphics.Canvas; 10import android.graphics.Color; 11import android.graphics.Paint; 12import android.os.Bundle; 13import android.view.Menu; 14import android.view.MenuItem; 15import android.view.MotionEvent; 16import android.view.Surface; 17import android.view.SurfaceHolder; 18import android.view.SurfaceView; 19import android.view.View; 20import android.view.View.OnTouchListener; 21 22public class MainActivity extends ActionBarActivity implements SurfaceHolder.Callback,Runnable{ 23 24 private SurfaceView sv; 25 private Thread mainLoop; 26 private SurfaceHolder holder; 27 private int width,height; 28 private ArrayList<Circle> circle = new ArrayList<Circle>(); 29 private int moveX,moveY; 30 private Paint paint; 31 32 @Override 33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 setContentView(R.layout.activity_main); 36 37 sv = (SurfaceView)findViewById(R.id.surfaceView1); 38 holder = sv.getHolder(); 39 holder.addCallback(this); 40 41 sv.setOnTouchListener(new OnTouchListener() { 42 43 @SuppressLint("ClickableViewAccessibility") @Override 44 public boolean onTouch(View v, MotionEvent event) { 45 doTouch(event); 46 return false; 47 } 48 }); 49 50 } 51 52 private void doTouch(MotionEvent e){ 53 //タッチされた座標x,y 54 int x = (int)e.getX(); 55 int y = (int)e.getY(); 56 57 for(int i = 0;i < circle.size();i++){ 58 Circle c = circle.get(i); 59 60 int diffX = x - c.getX(); 61 int diffY = y - c.getY(); 62 63 if(diffX * diffX + diffY * diffY < 10000){ 64 circle.remove(i); 65 if(i > 0){ 66 i--; 67 } 68 } 69 } 70 71 if(circle.size() <= 0){ 72 for(int i=0;i < 5;i++){ 73 x = (int)(Math.random() * (width - 200)) + 30; 74 y = (int)(Math.random() * (height - 200)) + 30; 75 int red = (int)(Math.random() * 255); 76 int green = (int)(Math.random() * 255); 77 int blue = (int)(Math.random() * 255); 78 paint = new Paint(); 79 paint.setColor(Color.rgb(red, green, blue)); 80 moveX = (int)(Math.random() * 60 - 30); 81 moveY = (int)(Math.random() * 60 - 30); 82 83 Circle c = new Circle(x,y,paint,moveX,moveY); 84 circle.add(c); 85 } 86 87 } 88 89 } 90 91 @Override 92 public boolean onCreateOptionsMenu(Menu menu) { 93 // Inflate the menu; this adds items to the action bar if it is present. 94 getMenuInflater().inflate(R.menu.main, menu); 95 return true; 96 } 97 98 @Override 99 public boolean onOptionsItemSelected(MenuItem item) { 100 // Handle action bar item clicks here. The action bar will 101 // automatically handle clicks on the Home/Up button, so long 102 // as you specify a parent activity in AndroidManifest.xml. 103 int id = item.getItemId(); 104 if (id == R.id.action_settings) { 105 return true; 106 } 107 return super.onOptionsItemSelected(item); 108 } 109 110 @Override 111 public void run() { 112 int moveX = 10; 113 int moveY = 10; 114 115 for(int i=0;i < 5;i++){ 116 int x = (int)(Math.random() * (width - 200)) + 30; 117 int y = (int)(Math.random() * (height - 200)) + 30; 118 int red = (int)(Math.random() * 255); 119 int green = (int)(Math.random() * 255); 120 int blue = (int)(Math.random() * 255); 121 paint = new Paint(); 122 paint.setColor(Color.rgb(red, green, blue)); 123 moveX = (int)(Math.random()*60 - 30); 124 moveY = (int)(Math.random()*60 - 30); 125 Circle c = new Circle(x,y,paint,moveX,moveY); 126 circle.add(c); 127 } 128 129 while(mainLoop != null){ 130 Canvas canvas = holder.lockCanvas(); 131 if(canvas == null){ 132 continue; 133 } 134 canvas.drawColor(Color.CYAN); 135 136 for(Circle c : circle){ 137 c.move(); 138 if(c.getX() + 30 > width || c.getX() - 30 < 0){ 139 c.reverseX(); 140 } 141 if(c.getY() + 30 > height || c.getY() - 30 < 0){ 142 c.reverseY(); 143 } 144 canvas.drawCircle(c.getX(), c.getY(), 30, c.getPaint()); 145 } 146 147// canvas.drawColor(Color.GREEN); 148// canvas.drawCircle(x, y, 30, paint); 149 150 151 holder.unlockCanvasAndPost(canvas); 152 } 153 } 154 155 @Override 156 public void surfaceCreated(SurfaceHolder holder) { 157 mainLoop = new Thread(this); 158 159 } 160 161 @Override 162 public void surfaceChanged(SurfaceHolder holder, int format, int width, 163 int height) { 164 this.width = width; 165 this.height = height; 166 mainLoop.start(); 167 168 } 169 170 @Override 171 public void surfaceDestroyed(SurfaceHolder holder) { 172 mainLoop = null; 173 } 174} 175

java

1package surfaceviewsample0306; 2 3 4import android.graphics.Paint; 5 6public class Circle { 7 int x; 8 int y; 9 int moveX; 10 int moveY; 11 12 Paint paint; 13 14 public Circle(int x,int y,Paint paint,int moveX,int moveY){ 15 this.x = x; 16 this.y = y; 17 this.paint = paint; 18 this.moveX = moveX; 19 this.moveY = moveY; 20 } 21 22 public void move(){ 23 this.x += moveX; 24 this.y += moveY; 25 } 26 27 public void reverseX(){ 28 this.moveX = (-1) * this.moveX; 29 } 30 31 public void reverseY(){ 32 this.moveY = (-1) * this.moveY; 33 } 34 35 public int getMoveX() { 36 return moveX; 37 } 38 public void setMoveX(int moveX) { 39 this.moveX = moveX; 40 } 41 public int getMoveY() { 42 return moveY; 43 } 44 public void setMoveY(int moveY) { 45 this.moveY = moveY; 46 } 47 public Paint getPaint() { 48 return paint; 49 } 50 public void setPaint(Paint paint) { 51 this.paint = paint; 52 } 53 public int getX() { 54 return x; 55 } 56 public void setX(int x) { 57 this.x = x; 58 } 59 public int getY() { 60 return y; 61 } 62 public void setY(int y) { 63 this.y = y; 64 } 65 66} 67

xml

1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:id="@+id/LinearLayout1" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 tools:context="jp.ac.hal.surfaceviewsample0306.MainActivity" > 8 9 <SurfaceView 10 android:id="@+id/surfaceView1" 11 android:layout_width="match_parent" 12 android:layout_height="match_parent" /> 13 14</LinearLayout>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

1-Circleのフィールドに画像フラグを追加する。
2-タッチイベント処理時にタッチ座標が円の中かどうかを判定する。
3-タッチ座標が円の中なら画像フラグをオンにする。
4-描画時に画像フラグを判定し、フラグがオンなら画像を表示する。

投稿2017/03/08 11:51

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問