EditText getting out of GridLayout

眉间皱痕 提交于 2019-11-30 15:58:39
Nicolas

Thanks to @Jack I found the solution: don't put any layout_width to the label, the gridlayout will handle it. Add android:layout_gravity="fill_horizontal" and android:layout_width="0dp" to the 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>
Jack

Okay, this problem seems to tricker than it seems.

To stop the TextView label pushing the EditText off of the screen.

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

But you're then left with a problem where adding text to the EditText squishes the TextView untils you can't see it.

Try what was done in this answer which seems to be a good compromise.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!