2015-11-02 50 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。 –