亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何根據點數組列表畫圓?

如何根據點數組列表畫圓?

翻閱古今 2022-11-10 15:12:46
我正在創建一個測試游戲,其中一個圓圈在被觸摸時將移動到點數組列表中的選定位置。但是,單擊時似乎無法移動到點的下一個位置。你能幫我找出問題出在哪里以及我可以使用什么解決方案嗎?public class EyeTestActivity extends AppCompatActivity  {private GestureDetectorCompat mDetector;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,            WindowManager.LayoutParams.FLAG_FULLSCREEN);    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    setContentView(new TestView(this));    // get the gesture detector    mDetector = new GestureDetectorCompat(EyeTestActivity.this, new SwipeGestureDetector());}public boolean onTouchEvent(MotionEvent motionEvent) {    this.mDetector.onTouchEvent(motionEvent);    return super.onTouchEvent(motionEvent);}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {    super.dispatchTouchEvent(ev);    return mDetector.onTouchEvent(ev);}public class TestView extends View {    public ArrayList<Point> pointlist;    Paint paint;    public TestView(Context context) {        super(context);        init();        setFocusable(true);        setFocusableInTouchMode(true);        createPointList();    }    public void init() {        paint = new Paint();        paint.setColor(Color.WHITE);        paint.setStrokeWidth(5);        paint.setStyle(Paint.Style.STROKE);    }我希望在打印時繪制下一個圓圈。
查看完整描述

1 回答

?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

首先,您應該參考您的TestView布局。


public class EyeTestActivity extends AppCompatActivity  {


    private GestureDetectorCompat mDetector;

    private TestView tv;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);


     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

        WindowManager.LayoutParams.FLAG_FULLSCREEN);

     this.requestWindowFeature(Window.FEATURE_NO_TITLE);

     tv = new TestView(this);

     setContentView(tv);

     // get the gesture detector

     mDetector = new GestureDetectorCompat(EyeTestActivity.this, new SwipeGestureDetector());


}

然后,在您的onScroll事件中,您應該測試e2而不是e1


@Override

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    if (e2.getAction() == MotionEvent.ACTION_MOVE) {

        z++;

       if (z >= 120) {   // zero based arraylist, so, >= 120

           z = 0;

       }

       tv.invalidate; // this to redraw the point

    }

    return true;

}

我認為你createPointList沒有做你想做的事。您正在創造 120 次相同的點!總計 120 * 5 * 24 = 14.400 點!


它應該是


for (int i = 1; i <= 5; i++) {

    float a = 100 * i;

    float b = 100 * i;

    for (int j = 1; j <= 24; j++) {

        float x = (float) (a * Math.sin(Math.toRadians(15 * j)));

        float y = (float) (b * Math.cos(Math.toRadians(15 * j)));

        pointlist.add(new Point((int)x, (int)y));

    }

}


查看完整回答
反對 回復 2022-11-10
  • 1 回答
  • 0 關注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號