EditText exits GridLayout

I am trying to create a view using EditText and its associated label. I put them in a GridLayout. EditText is in the last column, and the text seems to exit the screen.

<LinearLayout 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"
tools:context="mobi.designmyapp.osmtemplate.note.NoteActivity"
android:orientation="vertical">

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2"
    android:rowCount="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:labelFor="@+id/comment_edit_text"
        android:text="@string/comment_label"
        android:padding="8dp"
        android:textColor="@color/background_material_dark"
        android:maxLines="5"
        />

    <EditText
        android:id="@+id/comment_edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/comment_text_hint"/>

</GridLayout>

+4
source share
2 answers

Thanks to @Jack, I found a solution: do not put on the label layout_width, gridlayout will handle it. Add android:layout_gravity="fill_horizontal"and android:layout_width="0dp"to editText.

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2"
    android:rowCount="1">

    <TextView
        android:labelFor="@+id/comment_edit_text"
        android:text="@string/comment_label"
        android:padding="8dp"
        android:textColor="@color/background_material_dark"/>

    <EditText
        android:id="@+id/comment_edit_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:hint="@string/comment_text_hint"/>
</GridLayout>
+7
source

Well, this problem seems more complicated than it seems.

To stop the tag TextViewby tapping EditTexton the screen.

<TextView
    android:layout_width="0dp"
    android:layout_gravity="fill_horizontal" /> 

But you still have a problem with adding text to EditText, dropping TextViewuntil you see it.

, , .

+3

All Articles