Android Wear上的奇怪渲染问题

时间:2014-09-04 16:39:47

标签: java android

我正在开发一个Wear表面,我的输出非常不寻常。有一个神秘的圆形区域,其中一些子视图没有完全渲染。有趣的是我从不在视图中添加圆圈。

以下是输出的屏幕截图:

Screenshot of the watch face on a moto 360 emulator

奇怪的是时钟指针输出很好,它们首先被添加到视图中。以下是绘制线条的代码片段:

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);
}

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

您可以正确计算外部起点和角度,但长度会发生什么变化?检查边距!