简体   繁体   中英

Enlarge edittext in android by code when click a button

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

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) .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM