0

I tried to create an edittext textbox that will compute the width and height automatically by using the WRAP_CONTENT way. However, at some point of time I will need the actual height of the edit text, but I tried using layout params and getWidth(), getHeight(), I am not being returned with the values I will require.

Anyone have got any idea how can I go about this?

footprint.
  • 11
  • 2
  • Why do you need the actual height? Tell us more about what you are trying to achieve. – Cristian Aug 22 '11 at 17:40
  • @Cristian I am trying to create a simple border outside the edittext when I click a specific button, maybe instead you can tell me what would be a better way of doing that? – footprint. Aug 22 '11 at 17:48
  • What about changing the background of the `EditText`? That way android will take care of apply the border correctly. (yes, background; the background of an EditText contains also the drawing information of its border) – Cristian Aug 22 '11 at 17:54
  • @Cristian the border will be just a simple black line at each side of the edittext, but by applying the background, it will turn my whole edittext black? – footprint. Aug 22 '11 at 17:57
  • It will work fine just like you want if you create the appropriate nine-patch image. – Cristian Aug 22 '11 at 18:14
  • @Cristian i found another solution at [Question: Border texture for a View](http://stackoverflow.com/questions/3263611/border-for-an-image-view-in-android) which can be a feasible solution i need, but it seems that I have problems inflating it, [Question: Problems with drawing a border in android](http://stackoverflow.com/questions/7151723/problems-with-drawing-a-border-in-android) maybe you can help me with this instead? – footprint. Aug 22 '11 at 18:19

1 Answers1

0

You need to call view.layout() and then view.measure() in order for those values to be available to you prior to actual "layout" and display on the screen.

You need to be careful with wrap_content, though, because if your content is not already present in the view, it will not return the values you're looking for.

Hope this helps.

Codeman
  • 12,157
  • 10
  • 53
  • 91