开发者

EditText problem

开发者 https://www.devze.com 2023-03-10 10:06 出处:网络
I\'ve got an EditText... <EditText android:id=\"@+id/box\" android:autoText=\"true\" android:layout_width=\"fill_parent\" android:layout_height=\"45dip\"

I've got an EditText...

 <EditText android:id="@+id/box" android:autoText="true"
 android:layout_width="fill_parent" android:layout_height="45dip"
 android:singleLine="true" android:hint="Enter" />

Is it possible to make the text only appear up on till say... 50dip from the end of the EditText?

So when typing a query it'd look like

开发者_运维知识库 ____________________
 |y query is cool   |
 --------------------

while typing my query is cool


You can use paddingRight in this case (assuming I understood you correctly). Here is an example:

 <EditText android:id="@+id/box"
        android:autoText="true"
        android:layout_width="fill_parent"          
        android:layout_height="wrap_content"
        android:paddingRight="50dp"                                     
        android:singleLine="true"
        android:hint="Enter" 
        android:text="1234567890ABCDEF-1234567890ABCDEF"/>

EditText problem


The best alternative is to create your own nine-patch file and decide exactly how much padding you want.

See my answer here for a quick intro: How to create android spinner without down triangle on the right side of the widget

and the official docs here:

  • http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
  • http://developer.android.com/guide/developing/tools/draw9patch.html

Then, you should use

android:gravity="right"

inside your EditText


im a little confused also as to what you were going for, my first thought would be to add

<EditText android:id="@+id/box"
android:autoText="true"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:singleLine="true"
android:ellipsize="start"
android:hint="Enter" />

but maybe that wasn't what you meant? you could use this in combination with the techniques listed about so that the user wouldn't be confused by the missing characters.

0

精彩评论

暂无评论...
验证码 换一张
取 消