TextInputLayout动画文本时文本编程方式设置重叠 [英] TextInputLayout animation overlaps the text when the text is set programmatically

本文介绍了TextInputLayout动画文本时文本编程方式设置重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 TextInputLayout 设计支持库22.2.1 的。

我设置的EditText值编程,并出现在屏幕的时候,我可以看到TextInputLayout的提示文本内重叠,朝着浮动位置之前。

I set the value of the EditText programmatically, and when the screen appears, I can see that the hint of the TextInputLayout overlaps the text inside, before moving in the floating position.

下面一个简单的布局:

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hint1" />

    </android.support.design.widget.TextInputLayout> 

在我的活动

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        EditText e1 = (EditText) findViewById(R.id.editText1);
        e1.setText("TEXT TEST 1");
   }

有谁知道一个解决办法?

Does anyone know a workaround?

推荐答案

目前唯一的避免这种行为的方法是将的EditText 编程方式添加。

Currently the only way to avoid this behavior is to add the EditText programmatically.

  1. 创建一个 TextInputLayout 没有的EditText 。以编程方式或通过XML通胀 - 无所谓,但它必须是空的
  2. 创建的的EditText 键,其文本设置为任何你需要的。
  3. 添加 EDITTEXT TextInputLayout
  1. Create a TextInputLayout without the EditText. Programmatically or via XML inflation - doesn't matter, but it has to be empty.
  2. Create the EditText and set its text to whatever you need.
  3. Add the EditTExt to the TextInputLayout.

下面是一个例子:

TextInputLayout til = (TextInputLayout) findViewById(R.id.til);
til.setHint(R.string.hint);

EditText et = new EditText(getContext());
et.setText(value);

til.addView(et);

已更新21/08/2015与设计库V23:

通过设计支持库V23可以禁用动画:

With the design support library v23 you can disable the animation:

只是<一href="https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setHintAnimationEnabled(boolean)"相对=nofollow>使用:

textInputLayout.setHintAnimationEnabled(boolean)

下面的<一个问题href="https://$c$c.google.com/p/android/issues/detail?id=179776&can=1&q=label%3AVersion-Support-23&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars"相对=nofollow>谷歌跟踪。

这篇关于TextInputLayout动画文本时文本编程方式设置重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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