我如何在GridLayout布局由方二EditTexts一边给对方? [英] How do I layout two EditTexts side by side to each other in a GridLayout?

查看:190
本文介绍了我如何在GridLayout布局由方二EditTexts一边给对方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个EditTexts。我想每一个占用用户界面屏幕宽度的一半。

下面是我的XML布局文件。只有最左边的EditText(到期日),正显示出,所以我在这里清理失去了一些东西。应显示最右边的EditText是适当的时候。请指教。

  ....
< android.support.design.widget.TextInputLayout
    机器人:ID =@ + ID / DueDate_text_input_layout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_row =4
    机器人:layout_column =0>< com.example.jdw.thirdscreen.ListenerEditText
    机器人:ID =@ + ID / FEditText
    机器人:提示=截止日期
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =match_parent
    机器人:layout_weight =1
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentStart =真
    机器人:layout_gravity =开始
    安卓的inputType =TEXT | textCapSentences | textNoSuggestions
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:文字颜色=#FFFFFF
    机器人:单线=真
    机器人:最大长度=51
    机器人:imeOptions =actionNext | flagNoExtractUi
    机器人:layout_marginBottom =8DP
    机器人:nextFocusRight =@ + ID / DueTime_text_input_layout>< /com.example.jdw.thirdscreen.ListenerEditText>
< /android.support.design.widget.TextInputLayout>< android.support.design.widget.TextInputLayout
    机器人:ID =@ + ID / DueTime_text_input_layout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_row =4
    机器人:layout_column =1>< com.example.jdw.thirdscreen.ListenerEditText
    机器人:ID =@ + ID / GEditText
    机器人:提示=适当的时候
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =match_parent
    机器人:layout_weight =1
    机器人:layout_alignParentRight =真
    机器人:layout_alignParentEnd =真
    机器人:layout_gravity =开始
    安卓的inputType =TEXT | textCapSentences | textNoSuggestions
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium
    机器人:文字颜色=#FFFFFF
    机器人:单线=真
    机器人:最大长度=51
    机器人:imeOptions =actionNext | flagNoExtractUi
    机器人:layout_marginBottom =8DP
    机器人:nextFocusDown =@ + ID / saveButton>< /com.example.jdw.thirdscreen.ListenerEditText>
< /android.support.design.widget.TextInputLayout>
...


解决方案

使用重量属性,可用自21 API

 <网格布局的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s的android:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=横向
    工具:上下文=。MainActivity
    机器人:rowCount等=4
    机器人:列数=2>    <的EditText
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / EDITTEXT
        机器人:layout_gravity =fill_horizo​​ntal
        机器人:layout_columnWeight =1/>    <的EditText
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / editText2
        机器人:layout_gravity =fill_horizo​​ntal
        机器人:layout_columnWeight =1/>
< /网格布局>

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

解决方案

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>

这篇关于我如何在GridLayout布局由方二EditTexts一边给对方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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