Skip to content Skip to sidebar Skip to footer

How To Get A Views Coordinates In Constraintlayout

I've seven buttons in a vertical chain using a landscape constraint layout. At run time I size my buttons so they fit between the appbar and navigation bar. I also position a hor

Solution 1:

I found what I was doing incorrectly. I used the following to get the center points.

 final int lineStartX = ((ConstraintLayout.LayoutParams) vBtn1.getLayoutParams()).leftMargin + (vBtn1.getMeasuredWidth() / 2)+vBtn1.getLeft();
            final int lineStartY = ((ConstraintLayout.LayoutParams) vBtn1.getLayoutParams()).topMargin + (vBtn1.getMeasuredHeight() / 2)+vBtn1.getTop();
            final int lineEndX = ((ConstraintLayout.LayoutParams) vBtn2.getLayoutParams()).leftMargin + (vBtn2.getMeasuredWidth() / 2)+vBtn2.getLeft();
            final int lineEndY = ((ConstraintLayout.LayoutParams) vBtn2.getLayoutParams()).topMargin + (vBtn2.getMeasuredHeight() / 2)+vBtn2.getTop();

Post a Comment for "How To Get A Views Coordinates In Constraintlayout"