Android TextInputLayout/EditText不是完整大小,并且会截断文本 [英] Android TextInputLayout/EditText is not full size and cuts off text

查看:170
本文介绍了Android TextInputLayout/EditText不是完整大小,并且会截断文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含计算器的片段(只有三个TextInputEditTexts用来监听输入).

I have a fragment which contains a calculator (Just three TextInputEditTexts which listen for input).

这些输入在RelativeLayout中列出,如下所示-

These inputs are set out in a RelativeLayout as shown below-

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingBottom="16dp">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/binomial_probability_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/label_probability"
        android:paddingBottom="16dp">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/binomial_probability_input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:inputType="numberDecimal"/>
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/binomial_trials_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/label_trials"
        android:paddingBottom="16dp"
        android:layout_below="@+id/binomial_probability_wrapper">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/binomial_trials_input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:inputType="numberSigned"/>
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/binomial_successes_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/label_successes"
        android:paddingBottom="16dp"
        android:layout_below="@+id/binomial_trials_wrapper">
        <android.support.design.widget.TextInputEditText
            android:id="@+id/binomial_successes_input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:inputType="numberSigned"/>
    </android.support.design.widget.TextInputLayout>

</RelativeLayout>

我也尝试过将LinearLayout与每个输入放在单独的行上,但是结果相同.

I have also tried using a LinearLayout with each input on a separate row, but that had the same result.

如您在这张图片中看到的那样-

As you can see in this image-

底部输入被切断.如果我在屏幕上进行测量,显然尺寸会有所不同,但是Android会为每个布局和输入的高度返回相同的值.

the bottom input is cut off. If I measure it on my screen it is clearly a different size, but Android returns the same value for the heights of each layout and input.

欢迎提出任何有关解决此问题的建议.

Any suggestions as to how to fix this are welcome.

一些额外的信息.布局范围表明,文本光标实际上比底部TextInputEditText的高度高.顶部的高度正确.

Some extra information. The layout bounds show that the text cursor is actually taller than the height of the bottom TextInputEditText. The top have the correct height.

第二次我在下面添加了一个TextView(用于输出),现在将其截断,而TextInputEditText现在与其他输入相同.

Second edit: I added the a TextView below (For output) and that is now cut off, while the TextInputEditText is now the same as the others.

推荐答案

在官方github页面上说:

As saying in official github page:

TextInputLayout为填充和轮廓提供两种高度变化 文本字段,标准且密集.两种框样式均默认为 标准高度.

TextInputLayout provides two height variations for filled and outline text fields, standard and dense. Both box styles default to the standard height.

为了减小文本框的高度,可以使用密集 样式,这将减少文本框中的垂直填充.你 可以通过将适当的样式应用于您的样式来实现此目的 TextInputLayoutTextInputEditText,取决于您是否 使用填充或轮廓文本字段

In order to reduce the height of a text box, you can use a dense style, which will reduce the vertical padding within the text box. You can achieve this by applying the appropriate styles to your TextInputLayout and TextInputEditText, depending on whether you are using a filled or outline text field

因此,请尝试将@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense应用于您的TextInputLayout或更改TextInputEditText的填充

So try to apply @style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense to your TextInputLayout or change padding for TextInputEditText

这篇关于Android TextInputLayout/EditText不是完整大小,并且会截断文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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