Left align TextView to text inside EditText?

I would like to align the text in the TextView with the text inside the EditText that is directly below it. Is this possible without using tricks to fill?

If not, is it because he is discouraged? I could see that this was discouraging because it could confuse the user with the lack of distinction between the two controls.

enter image description here

Here is the layout that created the screenshot above:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/text_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:text="Please align my first character" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/text_view" android:hint="To my first character" /> </RelativeLayout> 
+4
source share
3 answers

No, you cannot do this without using a pad or layout_margin . EditText has a background with borders and indentation, so its content area is slightly smaller than the TextView area. I think it’s normal to use a gasket in such situations.

+1
source

This may actually be misleading, but you can add a little bias to the TextView to make it look better. Use android:layout_marginLeft and select a value that suits your requirements. Hope this helps.

0
source

I feel that you will have to use the add-on for TextView . It seems to me that the first character in TextView and that in EditView NOT OFF. They also have different font sizes, so in fact it looks pretty natural, as it is now, or maybe with a few additions, but not too many. When filling in, be sure to consider users with different screen sizes and resolutions, so use dp when you fill with android:layout_marginLeft . For instance:

 <TextView android:id="@+id/text_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="5dp" android:text="Please align my first character" /> 

Hope this helps.

0
source

Source: https://habr.com/ru/post/1436860/


All Articles