0
我想画一个自定义视图中十字线的正确尺寸,获取自定义视图
@Override
public void onWindowFocusChanged(boolean hasWindowFocus)
{ super.onWindowFocusChanged(hasWindowFocus);
top=this.getTop()+(this.getTop()/10);
bottom=this.getBottom()-(this.getBottom()/10);
left=this.getLeft()+(this.getLeft()/10);
right=this.getRight()-(this.getRight()/10);
Log.e("graph",getTop()+":"+top+","+this.getBottom()+":"+bottom+","+this.getLeft()+":"+left+","+this.getRight()+":"+right);
}
我使用这个代码来获取上,下,左,视右坐标和调整第十部分作为填充。
的onDraw方法内,
canvas.drawLine(left, (bottom - top)/2, right, (bottom - top)/2, paint);
canvas.drawLine((right-left)/2,top,(right-left)/2,bottom,paint);
这两种方法来绘制该水平居中和垂直居中的线。我正在手机屏幕上显示此图。
我想有水平居中和垂直居中行,我该怎么办?
在http://developer.android.com/ reference/android/view/View.html,它写成“例如,调用getRight()类似于下面的计算:getLeft()+ getWidth()”所以我不thisnk它会有所作为。 –