2017-04-13 31 views
0

我正在使用android的TextInputLayout在EditText上顯示浮動標籤。Viewgroup裏面的TextInputLayout使浮動標籤不工作

但我想在EditText的左邊顯示一個ProgressBar,因此我在該相對佈局內的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> 

+0

哪裏是你的代碼先生的職位? – Remario

+0

我已經發布了代碼,即使代碼中有FrameLayout作爲子代,但不是相對於每個問題的佈局。 –

回答

0

該功能將不可用。在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把你TextInputLayoutProgressBar和設定進度

相關問題