Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put text on right centre of image view on constraint layout

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

like image 864
Pritish Avatar asked Mar 21 '18 12:03

Pritish


People also ask

How do I center align a view in constraint layout?

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.

How do I center an image in constraint layout in Android Studio?

You can use layout_constraintCircle for center view inside ConstraintLayout .

How do I change constraint layout?

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.


1 Answers

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

like image 51
Ketan Patel Avatar answered Nov 15 '22 14:11

Ketan Patel