-2

Im new to android programming, and facing a difficulty in understanding what to needs to be done. Im trying to create a line that will move according to time, an appointment app,similar to the attached photo. Each column is going to be a separate relative layout. How can i draw a line across all the layouts?

Image

2 Answers2

0

i think you have to user View for it and give height to 1px (if you want to make horizontal line if you want to create vertical line then set width to 1px and height as you like)with background color as you like.

<View android:layout_width="match_parent"
      android:layout_height="1px"
      android:background="#000000" />

Like this

  • Thanks for you time, I read a similar answer, the problem with your solution is it will be between the views and too difficult to be applied across multiple layouts. – Hussam El-Qaissy Apr 02 '17 at 22:35
0

I have cut a big round in android by now, I am going to answer my own question in case anyone faces the same problem.

I placed a frame layout as my main layout, placed an imageview and another linear layout (inside i nested my required layouts).

below is the code required to draw a horizontal line.

    //  get the ImageView
        ImageView image = (ImageView) view.findViewById(R.id.currentTime);

// get screen size
        DisplayMetrics displaymetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int screenWidth = displaymetrics.widthPixels;
        int screenHeight = displaymetrics.heightPixels;

// create a bitmap
        Bitmap bitmap = Bitmap.createBitmap((int) screenWidth, (int) screenHeight, Bitmap.Config.ARGB_4444);

//create the canvas, and assign it to the bitmap 
        Canvas canvas = new Canvas(bitmap);
//link the bitmap and the ImageVIew
        image.setImageBitmap(bitmap);
// create a paint object to draw the line
        Paint paint = new Paint();
        paint.setColor(Color.CYAN);
        paint.setStrokeWidth(10);
        int startx = 130;
        int starty = 100;
        int endx = 1000;
        int endy = 100;
//draw the line to the canvas
        canvas.drawLine(startx, starty, endx, endy, paint);