###実現したいこと
二か所に円を描画します。最終的には両方が描画されている状態を目指します。
###発生している問題
始めに描いた方の円がすべて消えてしまいます。
###該当のソースコード
java
1circlemake = new Runnable() { 2 @Override 3 public void run() { 4 //円のアニメーション描画 5 sw = 1; 6 cnten1a = cnten1a + 1; 7 cta.endraw(); 8 if (cnten1a < 22) {//0-5で円の収縮、6で的、17-22で円の収縮、23で的 9 cbrunHandler.postDelayed(circlemake, 50); 10 }else if (cnten1a == 22){ 11 cbrunHandler.removeCallbacks(circlemake); 12 } 13 } 14 }; 15 cbrunHandler.postDelayed(circlemake, 50); 16 } 17 public class Ct extends View { 18 private float r1-r6;//r1-r6はそれぞれの一番目の円の半径 19 ※省略してます。 20 private float r1b-r6b;//r1b-r6bはそれぞれの二番目の円の半径 21 ※省略してます。 22 private float cx;//cx,cyは一番目の円の座標 23 private float cy; 24 private float cxb;//cxb,cybは二番目の円の座標 25 private float cyb; 26 private int cnten1 = 0;//円を収縮させるアニメーションに用いる変数 27 private int cnten2 = 0;//円を収縮させるアニメーションに用いる変数 28 private int en1sw1 = 0;//第二if文に進むための変数 29 private int en1sw2 = 0;//第三if文に進むための変数 30 private int en1sw3 = 0;//第四if文に進むための変数 31 private int countb = 1;//元々は一定秒を測るための変数で、今はただのカウンター 32 public Ct(Context context){ 33 super(context); 34 //Log.d("gw", ctsgw); 35 //Log.d("gh", ctsgh); 36 } 37 //ここら辺にメソッドを置いて、初期化を行うべきか? 38 protected void onDraw(Canvas canvas){ 39 super.onDraw(canvas); 40 int gw = getWinWM();//privateにする 41 int gh = getWinHM(); 42 float tw = getTitlewidthc(); 43 float twc = getTitlewherec(); 44 float ty = getTitley(); 45 int r1l = 25; 46 int r2l = 25;//ここまで 47 float raden1 = (float) (20 * Math.PI / 180); 48 //String ctsgw = String.valueOf(gw); 49 //String ctsgh = String.valueOf(gh); 50 //Log.d("gw", ctsgw); 51 //Log.d("gh", ctsgh); 52 53 Paint pam = new Paint(); 54 55 if (sw == 1 && en1sw1 != 1 && en1sw2 != 1 && en1sw3 != 1){ 56 //ここにすべての処理を書いていく↓ 57 //第一の円 58 cnten1 = cnten1 + 1; 59 if (cnten1 == 5){ 60 en1sw1 = 1; 61 } 62 r1 = 3 + (5 * r1l) - (cnten1 * r1l);//3に収束するから割合じゃなくて良い 63 cx = (float) ((tw * Math.cos(raden1) / 11) + twc + tw - (tw * Math.cos(raden1))); 64 //String cxa = String.valueOf(tw * Math.cos(raden1) / 10); 65 //String cxb = String.valueOf(twc); 66 //String cxc = String.valueOf(tw * Math.cos(raden1)); 67 //Log.d("cxa", cxa); 68 //Log.d("cxb", cxb); 69 //Log.d("cxc", cxc); 70 cy = (float) ((tw * Math.sin(raden1) / 2) + ty); 71 pam.setColor(Color.argb(255, 0, 0, 0)); 72 pam.setStyle(Paint.Style.STROKE); 73 pam.setStrokeWidth(3); 74 canvas.drawCircle(cx, cy, r1, pam); 75 //ここにすべての処理を書いていく↑ 76 }else if (sw == 1 && en1sw1 == 1 && en1sw2 != 1 && en1sw3 != 1){//en1=左の円、sw1一番外に広がる円 77 78 r2 = (float) (tw * Math.cos(raden1) / 11);//60 79 pam.setColor(Color.argb(255, 0, 0, 0)); 80 pam.setStyle(Paint.Style.STROKE); 81 pam.setStrokeWidth(3); 82 canvas.drawCircle(cx, cy, r2, pam); 83 pam.setColor(Color.argb(255, 255, 255, 255)); 84 pam.setStyle(Paint.Style.FILL); 85 canvas.drawCircle(cx, cy, r2 - 1, pam); 86 r3 = r2 / 6 * 5;//r2 / 6 * 5; 87 pam.setColor(Color.argb(255, 0, 0, 0)); 88 pam.setStyle(Paint.Style.STROKE); 89 pam.setStrokeWidth(3); 90 canvas.drawCircle(cx, cy, r3, pam); 91 pam.setColor(Color.argb(255, 0, 0, 0)); 92 pam.setStyle(Paint.Style.FILL); 93 canvas.drawCircle(cx, cy, r3 - 1, pam); 94 r4 = r3 / 5 * 4; 95 pam.setColor(Color.argb(255, 0, 0, 0)); 96 pam.setStyle(Paint.Style.STROKE); 97 pam.setStrokeWidth(3); 98 canvas.drawCircle(cx, cy, r4, pam); 99 pam.setColor(Color.argb(235, 0, 0, 255)); 100 pam.setStyle(Paint.Style.FILL); 101 canvas.drawCircle(cx, cy, r4 - 1, pam); 102 r5 = r4 / 4 * 3; 103 pam.setColor(Color.argb(255, 0, 0, 0)); 104 pam.setStyle(Paint.Style.STROKE); 105 pam.setStrokeWidth(3); 106 canvas.drawCircle(cx, cy ,r5, pam); 107 pam.setColor(Color.argb(225, 255, 0, 0)); 108 pam.setStyle(Paint.Style.FILL); 109 canvas.drawCircle(cx, cy, r5 - 1, pam); 110 r6 = r5 / 3 * 2; 111 pam.setColor(Color.argb(255, 0, 0, 0)); 112 pam.setStyle(Paint.Style.STROKE); 113 pam.setStrokeWidth(3); 114 canvas.drawCircle(cx, cy, r6, pam); 115 pam.setColor(Color.argb(255, 255, 255, 128)); 116 pam.setStyle(Paint.Style.FILL); 117 canvas.drawCircle(cx, cy, r6 - 1, pam); 118 en1sw2 = 1; 119 120 }else if (sw == 1 && en1sw1 == 1 && en1sw2 == 1 && en1sw3 != 1){ 121 if (countb == 1) { 122 sleep(500); 123 } 124 String cxst = String.valueOf(cx); 125 String cyst = String.valueOf(cy); 126 String r2st = String.valueOf(r2); 127 Log.d("cx", cxst); 128 Log.d("cy", cyst); 129 Log.d("r2", r2st); 130 if (1 <= countb && countb <= 5) {//円の収縮 131 cnten2 = cnten2 + 1; 132 r1b = 3 + (5 * r2l) - (cnten2 * r2l); 133 cxb = (float) (tw / 9 * (-1 + (10 * Math.cos(raden1))) + twc); 134 cyb = (float) ((-11 * tw * Math.sin(raden1) / 18) + ty); 135 String cxblog = String.valueOf(cxb); 136 String cyblog = String.valueOf(cyb); 137 Log.d("cxb", cxblog); 138 Log.d("cyb", cyblog); 139 pam.setColor(Color.argb(255, 0, 0, 0)); 140 pam.setStyle(Paint.Style.STROKE); 141 pam.setStrokeWidth(3); 142 canvas.drawCircle(cxb, cyb, r1b, pam); 143 if (countb == 5) { 144 en1sw3 = 1; 145 } 146 countb = countb + 1; 147 } 148 }else if (sw == 1 && en1sw1 == 1 && en1sw2 == 1 && en1sw3 == 1){ 149 r2b = (float) (tw * Math.cos(raden1) / 9); 150 pam.setColor(Color.argb(255, 0, 0, 0)); 151 pam.setStyle(Paint.Style.STROKE); 152 pam.setStrokeWidth(3); 153 canvas.drawCircle(cxb, cyb, r2b, pam); 154 pam.setColor(Color.argb(255, 255, 255, 255)); 155 pam.setStyle(Paint.Style.FILL); 156 canvas.drawCircle(cxb, cyb, r2b - 1, pam); 157 r3b = r2b / 6 * 5;//r2 / 6 * 5; 158 pam.setColor(Color.argb(255, 0, 0, 0)); 159 pam.setStyle(Paint.Style.STROKE); 160 pam.setStrokeWidth(3); 161 canvas.drawCircle(cxb, cyb, r3b, pam); 162 pam.setColor(Color.argb(255, 0, 0, 0)); 163 pam.setStyle(Paint.Style.FILL); 164 canvas.drawCircle(cxb, cyb, r3b - 1, pam); 165 r4b = r3b / 5 * 4; 166 pam.setColor(Color.argb(255, 0, 0, 0)); 167 pam.setStyle(Paint.Style.STROKE); 168 pam.setStrokeWidth(3); 169 canvas.drawCircle(cxb, cyb, r4b, pam); 170 pam.setColor(Color.argb(235, 0, 0, 255)); 171 pam.setStyle(Paint.Style.FILL); 172 canvas.drawCircle(cxb, cyb, r4b - 1, pam); 173 r5b = r4b / 4 * 3; 174 pam.setColor(Color.argb(255, 0, 0, 0)); 175 pam.setStyle(Paint.Style.STROKE); 176 pam.setStrokeWidth(3); 177 canvas.drawCircle(cxb, cyb,r5b, pam); 178 pam.setColor(Color.argb(225, 255, 0, 0)); 179 pam.setStyle(Paint.Style.FILL); 180 canvas.drawCircle(cxb, cyb, r5b - 1, pam); 181 r6b = r5b / 3 * 2; 182 pam.setColor(Color.argb(255, 0, 0, 0)); 183 pam.setStyle(Paint.Style.STROKE); 184 pam.setStrokeWidth(3); 185 canvas.drawCircle(cxb, cyb, r6b, pam); 186 pam.setColor(Color.argb(255, 255, 255, 128)); 187 pam.setStyle(Paint.Style.FILL); 188 canvas.drawCircle(cxb, cyb, r6b - 1, pam); 189 } 190 } 191 public synchronized void sleep(long msec){ 192 try{ 193 wait(msec); 194 }catch (InterruptedException e){ 195 ///// 196 } 197 } 198 public void endraw(){ 199 invalidate(); 200 } 201 }
###判明したこと
if (countb == 1){
sleep(100);
}
よりも後ろでクリアされていると思われます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/24 07:59
2017/01/24 08:14
2017/01/24 08:37
2017/01/24 08:42
2017/01/24 09:42 編集
2017/01/24 09:46
2017/01/24 09:57
2017/01/24 10:45
2017/01/24 10:56 編集
2017/01/24 11:00 編集
2017/01/24 11:06 編集
2017/01/24 11:07
2017/01/24 11:14
2017/01/24 11:26
2017/01/24 11:31
2017/01/24 11:48
2017/01/24 11:56
2017/01/24 11:57