Излизане на EditText от GridLayout

Опитвам се да създам изглед с EditText и свързан етикет. Поставям ги в GridLayout. EditText е в последната колона и текстът сякаш излиза от екрана.

<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>


person Nicolas    schedule 15.06.2015    source източник
comment
Опитахте ли да промените ширината/височината на децата на match_parent?   -  person Jack    schedule 15.06.2015
comment
да, и даде същия резултат.   -  person Nicolas    schedule 15.06.2015
comment
От моя страна изглежда добре. Оформлението на мрежата дъщерно ли е за друг изглед? Напр.: RelativeLayout   -  person Jack    schedule 15.06.2015
comment
той е в linearLayout, текстът за редактиране изглежда излиза извън екрана приблизително с размера на моя етикет.   -  person Nicolas    schedule 15.06.2015
comment
Добре, разбрах го. Вижте моя отговор.   -  person Jack    schedule 15.06.2015


Отговори (2)


Благодарение на @Jack намерих решението: не поставяйте никакви layout_width към етикета, gridlayout ще се справи. Добавете android:layout_gravity="fill_horizontal" и android:layout_width="0dp" към 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>
person Nicolas    schedule 15.06.2015
comment
Ако имате няколко реда, всеки ред ще трябва да бъде променен, за да видите очакваното поведение. - person don't panic; 27.06.2017

Добре, този проблем изглежда по-измамен, отколкото изглежда.

За да спрете етикета TextView да избутва EditText от екрана.

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

Но след това оставате с проблем, при който добавянето на текст към EditText смачква TextView, докато не можете да го видите.

Опитайте какво е направено в този отговор, което изглежда е добър компромис.

person Jack    schedule 15.06.2015