Center vertical text image in EditText

What I'm trying to do is have a TextView, and to the right of it is an EditText, which takes up the rest of the space. The TextView should be vertical along the editText. Now I can do it with linearlayout, however I would prefer to do it in relativelayout mode.

<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:padding="10dp">
     <TextView
          android:id="@+id/loginText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Login:"
          android:paddingRight="20dp" />

<EditText
          android:id="@+id/login"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_toRightOf="@id/loginText" />

</RelativeLayout>
+3
source share
2 answers

What you want to do is perhaps using android:layout_alignBottomand android:layout_alignTopprovided to RelativeLayoutits children and android:gravityproperty TextView.

/ / . TextView, TextView EditText. TextView TextView.

, :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >
    <TextView android:id="@+id/user_name_label"
        android:text="@string/user_name"
        android:layout_width="wrap_content"
        android:layout_height="0dp" 
        android:layout_alignBottom="@+id/user_name_text"
        android:layout_alignTop="@id/user_name_text"
        android:layout_marginRight="5dp"
        android:gravity="center_vertical" />
    <EditText android:id="@id/user_name_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/user_name_label" />
</RelativeLayout>
+4

android:layout_gravity="center_vertical"

textview


+3

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


All Articles