2015-11-02 46 views
2

enter image description here顯示在EditText上的端部在機器人

不可編輯的文本欲如上所示爲URLName.How我可以達致這在圖像中在的EditText年底來顯示文本?文本不能被編輯。我在設計庫中使用TextInputLayout內的editText。在此先感謝

+1

@TimCastelijns請仔細閱讀問題。它完全不同的問題 –

+1

@ShivanshuVerma你怎麼看? –

+1

作者需要一個EditText,在該EditText上右側字段由用戶無法更改的靜態文本完成。我是嗎? @鬍子 –

回答

3
  • 創建一個LinearLayout。這個佈局內的一行例子是標題(即URL名稱)或文本輸入字段。

  • 將當前行的LinearLayout的背景設置爲自定義繪圖以創建細紅線。按照this的答案發表意見。

  • 對於您的問題中提到的URL輸入字段,在當前行內部的另一個LinearLayout內創建一個TextView和一個EditText

TextView將包含「.sitename.com」。將其設置爲wrap_content並給它一個weight0。對於您的EditText,請將其width設置爲0dp及其weight1。它現在應該填充所有剩餘的空間。爲兩者設置background@null

+0

我想利用最新的TextInputLayout這個EditText。 –

+0

這是正常的方法嗎?除了上面的解決方案,我有辦法實現這一點嗎? –

+0

@beardedbeast我從來沒有使用它,但不是'TextInputLayout'與'EditText'可以互換嗎? – PPartisan

1

這爲我工作:

<RelativeLayout 

     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
    <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:layout_alignParentLeft="true" 
      android:id="@+id/youeeditid" 
      android:layout_gravity="center" 
      /> 
    <TextView 
      android:id="@+id/text_hint" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:text="HintText" 
      android:textSize="18sp" 
      android:layout_marginRight="10dp" 
      android:textColor="#808080" 
      /> 
</RelativeLayout> 

這是有點棘手,但它是爲我工作。

如果你只想設置EditText上,那麼你可以在下面做:

1)EditText上的重力設置爲 「右」 和Ellipsize到 「結束」。

2)現在在onCreate()方法中寫入EditText的onclicklistener並將 重力設置爲「Left」。

3)或者您也可以在OnKeyListener上編程設置,其中檢查 如果edittext的長度等於零設置EditText的引力爲 左邊。

參考:Setting cursor to the right on an EditText with HINT Gravity to center

+0

我如何在TextInputLayout中實現這個?任何想法 ? –

+0

@bearded野獸:嘗試設置right | top – KishuDroid

+0

如果edittext增長,那麼它將重疊textview。 –