How do I layout two EditTexts side by side to each other in a GridLayout?

社会主义新天地 提交于 2019-12-12 03:39:24

问题


I have two EditTexts. I'd like each to take up half of the UI screen width.

Below is my xml layout file. Only the leftmost EditText ("Due Date") is showing so I'm clearing missing something here. The rightmost EditText that should be showing is the "Due Time". Please advise.

....
<android.support.design.widget.TextInputLayout
    android:id="@+id/DueDate_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_row="4"
    android:layout_column="0">

<com.example.jdw.thirdscreen.ListenerEditText
    android:id="@+id/FEditText"
    android:hint="Due Date"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_gravity="start"
    android:inputType="text|textCapSentences|textNoSuggestions"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#FFFFFF"
    android:singleLine="true"
    android:maxLength="51"
    android:imeOptions="actionNext|flagNoExtractUi"
    android:layout_marginBottom="8dp"
    android:nextFocusRight="@+id/DueTime_text_input_layout" >

</com.example.jdw.thirdscreen.ListenerEditText>
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/DueTime_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_row="4"
    android:layout_column="1">

<com.example.jdw.thirdscreen.ListenerEditText
    android:id="@+id/GEditText"
    android:hint="Due Time"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_gravity="start"
    android:inputType="text|textCapSentences|textNoSuggestions"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#FFFFFF"
    android:singleLine="true"
    android:maxLength="51"
    android:imeOptions="actionNext|flagNoExtractUi"
    android:layout_marginBottom="8dp"
    android:nextFocusDown="@+id/saveButton" >

</com.example.jdw.thirdscreen.ListenerEditText>
</android.support.design.widget.TextInputLayout>
...

回答1:


use weight property, available since API 21

<GridLayout 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:orientation="horizontal"
    tools:context=".MainActivity"
    android:rowCount="4"
    android:columnCount="2">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_gravity="fill_horizontal"
        android:layout_columnWeight="1" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:layout_gravity="fill_horizontal"
        android:layout_columnWeight="1" />
</GridLayout>


来源:https://stackoverflow.com/questions/32193484/how-do-i-layout-two-edittexts-side-by-side-to-each-other-in-a-gridlayout

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