Following is a part of my whole xml of constraint Layout.
<ImageView
android:id="@+id/img_apn_not_set"
style="@style/DeviceManagementImageView"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_sos"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view1" />
<TextView
android:id="@+id/tv_apn_not_set"
style="@style/DeviceManagementHeaderText"
android:text="Apn not set"
android:layout_marginTop="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/img_apn_not_set"
app:layout_constraintTop_toTopOf="@+id/img_apn_not_set" />
What I am trying to do is get the text view on exact centre on the right side of image view. In linear layout we achieve it mostly by gravity. Here I am using marginTop
to achieve the same . So can I do the same by using any property . Is there a property something like rightOfCentreOf
?
Thanks
Center a view horizontally, set layout_constraintLeft_toLeftOf and layout_constraintRight_toRightOf to parent. Center a view vertically, set layout_constraintTop_toTopOf and layout_constraintBottom_toBottomOf to parent. Align to the top left.
You can use layout_constraintCircle for center view inside ConstraintLayout .
Open the layout file (activity_main. xml) in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click LinearLayout and then choose Convert layout to ConstraintLayout from the context menu.
pls add one line in your textview
app:layout_constraintBottom_toBottomOf="@+id/img_apn_not_set"
also remove android:layout_marginTop="5dp"
hope it help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With