1

I want to know if its possible to enlarge a EditText in android from 0 until to fill its parent. I tried several things, but in the moment I have the LinearLayout and the EditText is added by code:

    <LinearLayout
        android:id="@+id/ll_buscarenlace"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.8"
        android:gravity="right" >

-

EditText et = (EditText) new EditText(this.act);
LinearLayout ll = (LinearLayout) this.act.findViewById(R.id.ll_buscarenlace);

    et.setWidth(0);
    ll.addView(et);

    for (int i=0; i<=ll.getWidth(); i++){
        et.setWidth(i);
        Thread.sleep(50);

    }

But this is one of many things that I tried to do. Thanks in advance

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • All these codes are in one java file? Please say no. – hakki Mar 06 '13 at 21:03
  • I don't seem to see any TextView being added? You're adding an EditText not a TextView. Or am I missing something? – Kakalokia Mar 06 '13 at 21:04
  • if you have more than one file. Please seperate it while posting here. Readers can't understand which code in which file. – hakki Mar 06 '13 at 21:09
  • See [this answer](http://stackoverflow.com/a/15182274/321697) – Kevin Coppock Mar 06 '13 at 21:21
  • These are in Layouts folder and src folder, as you know. Sorry, its a EditText, not TextView, Im so tired... This are two separate files, as you know – user1675150 Mar 06 '13 at 21:21
  • Another issue is Thread.sleep(50); This is very small time value. Because it is in miliseconds. 50ms is equal **0.05** secs When this code work correctly it seems like flash. If you try 5 seconds change value to 5000 – hakki Mar 06 '13 at 21:36
  • Why are you set LinearLayout's with to 0? Are not you trying resize EditText? – hakki Mar 06 '13 at 21:40

2 Answers2

0

By "make it go from zero to fill-parent", do you mean that you want it to initially be invisible and then, on a button click, become visible?

If so, you don't need to do any resizing - in the layout file set android:layout_width="fill_parent" and make it invisible with android:visibility="gone".

Then, in the onClickListener on your button, you can call et.setVisible(Visibility.VISIBLE).

drew moore
  • 31,565
  • 17
  • 75
  • 112
0

A possible solution: ScaleAnimation.

EditText editText = (EditText) findViewById(R.id.editText1);

Animation scaleAnimation = new ScaleAnimation(0, 1, 1, 1);
scaleAnimation.setDuration(750);
editText.startAnimation(scaleAnimation);

Not exactly what you're looking for since it scales rather than expands, but it may be of help. The effect is not bad either.

f20k
  • 3,106
  • 3
  • 23
  • 32
  • Nothing but excellent! Thank you f20k. Anyway, I added a modification to move from right to left: Animation scaleAnimation = new ScaleAnimation(0, 1,1,1,Animation.RELATIVE_TO_SELF,1.0f, Animation.RELATIVE_TO_SELF, 0.5f); – user1675150 Mar 07 '13 at 02:55