2014-09-04 50 views
1

我正在開發一個Wear手錶,我得到一個非常不尋常的輸出。有一個神祕的圈子區域,其中一些子視圖沒有完全呈現。有趣的是我從不在視圖中添加一個圓圈。Android Wear上怪異的渲染問題

下面是輸出的屏幕截圖:

Screenshot of the watch face on a moto 360 emulator

奇怪的是時鐘指針被輸出就好了,他們被添加到視圖第一。下面是繪製行代碼的SNIPPIT:

for(int i=1; i<=60; i++) { 
     int seconds = i; 
     int radius = (screenWidth/2); 
     int centre = (screenWidth/2); 
     int totalLimit = 60; 
     int currentValue = seconds; 
     int theta = (360/totalLimit) * currentValue; 

     double x = centre + radius * Math.cos(theta * Math.PI/180); 
     double y = centre + radius * Math.sin(theta * Math.PI/180); 

     float angle = (float) Math.toDegrees(Math.atan2(x - centre, y - centre)); 
     if (angle < 0) { 
      angle += 360; 
     } 
     if (angle > 180) 
      angle -= 180; 
     else 
      angle += 180; 


     View view = new View(this); 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1, radius); 
     params.leftMargin = (int)x; 
     params.topMargin = (int)y; 
     view.setPivotX(0); 
     view.setPivotY(0); 
     view.setRotation(-angle); 
     view.setBackgroundColor(Color.WHITE); 
     mWatchView.addView(view, params); 

     views.add(view); 
} 

回答

1

好所以,現在從外面畫線,我現在從外面畫線。這就解決了這個問題。

params.leftMargin = (int)(screenWidth-x); 
params.topMargin = (int)(screenWidth-y); 

也發生了變化取決於線的長度半徑我想

int length = 15; 
int width = 1; 
if (i == 10 || i == 20 || i == 30 || i == 40 || i == 50 || i == 60) { 
    length = 35; 
    width = 2; 
} 
if (i == 5 || i == 15 || i == 25 || i == 35 || i == 45 || i == 55) { 
    length = 25; 
    width = 2; 
} 
int seconds = i; 
int radius = (screenWidth/2)-length; 

下面是結果:

enter image description here

0

您正確計算外起點和角度,但長度會發生什麼?檢查邊距!

+0

感謝。我如何在x,y上添加視圖然後旋轉它,但仍保留其長度的任何提示? – Eeshwar 2014-09-04 17:23:36