EditText脱离GridLayout [英] EditText getting out of GridLayout

查看:91
本文介绍了EditText脱离GridLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个带有EditText和关联标签的视图.我将它们放在GridLayout中.EditText位于最后一列,文本似乎不显示在屏幕上.

I am trying to create a view with an EditText and a label associated. I am placing them in a GridLayout. The EditText is in the last column and the text seems to go out of 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>

推荐答案

感谢@Jack,我找到了解决方案:不要在标签上放置任何 layout_width ,gridlayout会处理它.将 android:layout_gravity ="fill_horizo​​ntal" android:layout_width ="0dp" 添加到editText.

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>

这篇关于EditText脱离GridLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆