Create “L” shape curved line with dynamic data

拥有回忆 提交于 2019-12-01 04:44:48

In this case I would use custom View with custom onDraw:

That is,

public class myView extended View {
public myView(Context ctx) {
super(ctx);
init();
}
public void init(){
paint = new Paint();
}
@Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
//loop here
      canvas.drawLine(0, 0, 20, 20, paint);//your some positions.
canvas.drawRect(....)
canvas.drawText(...)
    }
}

EDIT For your second example:

init() {

//rectangle background
mBGPaint = new Paint();
mBGPaint.setColor(0xFF0000FF);

//your text
mTXTPaint = new Paint();
mTXTPaint.setColor(0xFFFFFFFF);

//your line
mLINEPaint = new Paint();
mLINEPaint.setColor(0xFFFF00FF);

//rectangle border
mBRDPaint = new Paint();
mBRDPaint.setStyle(Style.STROKE);
mBRDPaint.setStrokeWidth(10);
mBRDPaint.setColor(0xFFFFFF00);
}

onDraw(...) {

//draw rect
canvas.drawRect(100,100,200,200,mBGPaint);
//draw rect border
canvas.drawRect(100,100,200,200,mBRDPaint);
//draw text
canvas.drawRect(100,100,mTXTPaint);
//draw line
canvas.drawLine(50, 150, 100, 150, mLINEPaint);
}

This is really a big question. And I think no one can give you a definitive answers for that.

My advise is baby steps:

1-Put a button on the screen and try to create 3 lines to get a crooked line effect. Calculate the length of all 3 parts of the crooked line by using a start point(at the beginning you can start from the middle of the screen) and end point(buttons final destination)

2- If you know start and end position for the button you can calculate the line2 length easily. For the line1 and line3 you also need to pass another parameter for your calculate function(by the way you should have it) where to start to crook.

After you complete this task then there are more. 3- You should then place 5 buttons on the screen and assemble their cooked lines by using the function you defined before. 4- According to your start and end point your cooked line should go up and down. 5- Now you are capable of creating cooked lines. It is time to calculate for the real task.

6- You should calculate the required space available and somehow figure out if the buttons will fit in. If not you should put the button in second lane and then use your magical L draw method to connect them to a calculated start position(you should have calculated the y position of the start points for every buttons.)

It is go on. Just try to split your assignment into little pieces and then try to complete each of them easily without any headache.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!