Saurav Ray
Saurav Ray

Reputation: 21

How do I add a vertical divider in android studio using ConstraintLayout

I want to add a ViewAnimator using ConstraintLayout. I did it using RelativeLayout but I am not able to do the same using ConstraintLayout. In fact there isn't any such option, there is horizontal and vertical divider. The screenshot given is what I want using ConstraintLayout, I did that with RelativeLayout. Here is the code for ViewAnimator

<ViewAnimator
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_marginTop="16dp"
        android:background="@android:color/darker_gray" />

I only need the vertical line

Just like this screenshot done using RelativeLayout

Upvotes: 2

Views: 3167

Answers (1)

Hesam Rasoulian
Hesam Rasoulian

Reputation: 1535

Set the height 0dp and then use topof and bottomof parent or any view.

    <ViewAnimator
    android:layout_width="1dp"
    android:layout_height="0dp"
    android:layout_marginTop="16dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="@android:color/darker_gray" />

also for vertical div you can use <View /> tag.

Upvotes: 4

Related Questions