Группа просмотра внутри TextInputLayout делает плавающую метку неработающей

Я использую Android TextInputLayout для отображения плавающей метки в EditText.

Но я хочу показать ProgressBar слева от EditText, поэтому я добавил относительный макет внутри TextInputLayout и EditText внутри этого относительного макета.

при этом плавающая метка не работает.

Если я удалю относительный макет из TextInputLayout и сделаю его прямыми дочерними элементами EditText, тогда это сработает.

Так что EditTExt должен быть прямым дочерним элементом TextInputLayout, и если да, то как мы можем поместить другой виджет в EditTexts, оставленный как ProgressBar.

Поскольку TextInputLayout унаследован от LinearLayout, добавление к нему дочерних элементов добавит дочерние элементы по вертикали, но я хочу добавить представления поверх EditText.

<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/holderName"

android:layout_height="wrap_content"

 android:layout_width="match_parent">


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<android.support.design.widget.TextInputEditText
    android:id="@+id/etField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Name"


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

    <ProgressBar
        android:id="@+id/progress"
        style="?android:attr/progressBarStyle"
        android:layout_width="16dp"
        android:layout_height="match_parent"
        android:indeterminateTint="@color/primary"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="15dp"
        android:visibility="visible"
        />


</FrameLayout>


person Shofiqul Alam    schedule 13.04.2017    source источник
comment
где ваш код, сэр?   -  person Remario    schedule 13.04.2017
comment
Я разместил код, хотя код имеет FrameLayout как дочерний элемент, а не относительный макет в соответствии с вопросом.   -  person Shofiqul Alam    schedule 13.04.2017


Ответы (2)


Решение состоит в том, чтобы обернуть TextInputLayout и ProgressBar с FrameLayout следующим образом:

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/holderName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/etField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Name" />

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

        <ProgressBar
            android:id="@+id/progress"
            style="?android:attr/progressBarStyle"
            android:layout_width="16dp"
            android:layout_height="match_parent"
            android:layout_gravity="right|center_vertical"
            android:layout_marginRight="15dp"
            android:indeterminateTint="@color/primary"
            android:visibility="visible" />
    </FrameLayout>
person SAZ    schedule 03.12.2018

Эта функция недоступна. В addView() он напрямую ищет файл EditText.

Вот код

@Override
public void addView(View child, int index, final ViewGroup.LayoutParams params) {
    if (child instanceof EditText) {
          mInputFrame.addView(child, new FrameLayout.LayoutParams(params));

          // Now use the EditText's LayoutParams as our own and update them to make enough space
          // for the label
          mInputFrame.setLayoutParams(params);
          updateInputLayoutMargins();

          setEditText((EditText) child);
    } else {
          // Carry on adding the View...
          super.addView(child, index, params);
    }
}

Итак, первый потомок должен быть типа EditText.

Если вам нужна эта функциональность, то внутри RelativeLayout возьмите свои TextInputLayout и ProgressBar и установите позиции Progressbar

person Nigam Patro    schedule 29.08.2017