如何在所有屏幕上对齐下图中的textview

时间:2015-02-24 12:00:16

标签: android

我必须在所有屏幕的给定图像中的不同点上对齐文本。有没有人可以帮助我实现这个目标?

enter image description here

1 个答案:

答案 0 :(得分:0)

使用XML标记来实现您的UI非常困难,但有Canvas个方法可以轻松绘制所有基元。

样品:

private Paint circlePaint;
private Paint linePaint;
private Paint textPaint;
private String[] titles;
private float circleRadius;

@Override protected void onDraw(Canvas canvas) {

    float height = getHeight();
    float width = getWidth();
    float circleX;//set initial X depending on width and height of screen
    float circleY;//set initial Y

    for (int i = 0; i < titles.length; i++) {
        String title = titles[i];
        canvas.drawCircle(circleX, circleY, circleRadius, circlePaint);
        canvas.drawText(title, circleX + circleRadius, circleY, textPaint);

        float nextCircleX;//calculate next X coordinate
        float nextCircleY;//calculate next Y coordinate

        canvas.drawLine(circleX, circleY, nextCircleX, nextCircleY, circlePaint);

        circleX = nextCircleX;
        circleY = nextCircleY;
    }
}