开发者

Android EditText offset for the text?

开发者 https://www.devze.com 2023-04-05 09:48 出处:网络
I\'ve created a background drawable for my EditText, but the text showed up IN the image border. I fixed this by setting \'scrollX to -12dip, and this seemed to word in Eclipse, in the graphical layou

I've created a background drawable for my EditText, but the text showed up IN the image border. I fixed this by setting 'scrollX to -12dip, and this seemed to word in Eclipse, in the graphical layout viewer (pic 1开发者_运维问答). However on the device it still shows up through the image. I've referenced to my background drawable through a xml file if that matters.

In Eclipse and a screenshot http://img28.imageshack.us/img28/9954/nieuwbitmapafbeelding.png

yes, i know the second pic is different, but that's just because i focussed on the view, the problem stays even if I unfocus. :'(

.

EDIT

I now completely remade the image(s), and used draw9patch. The text offset was fixed, however since I used a vertical gradient in my image, I selected all the pixels (minus the actual border) to prevent having one part gradient -> stretched solid color part -> gradient. Now the height of the background drawable always remains very big.

How is this usually done, if there's a gradient in the image? Probably if you create the image small to begin with, you won't get a very smooth gradient.

How do I fix my problem, and how should it be done?


If you use the android:paddingLeft="" attribute in your EditText, it will move the TextView inside it over a specified number of pixels.

Example:

android:paddingLeft="30dp" will move your text to the right 30 density-independent pixels.


How have you actually created the background image? If it's the full image then that's not the best way to do this.

You should be creating a 9-patch image to use as the background; http://developer.android.com/guide/developing/tools/draw9patch.html


If you use editText.setPadding(), it may give you the spacing you need for the text to shift over. It might also apply padding to the background resource as well though. But try it out


Just a suggestion, not a solution...

You can use RelativeLayout, and in XML, use some attributes like alignParentBotton or alignParentLeft something like that instead of absolute position coordinators. If you use the absolute coordinators, sometimes, your ui seems different on different devices.

0

精彩评论

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