简体   繁体   English

单击按钮时通过代码在android中放大edittext

[英]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. 我想知道是否有可能在Android中将EditText从0放大到填充其父级。 I tried several things, but in the moment I have the LinearLayout and the EditText is added by code: 我尝试了几件事,但是现在我有了LinearLayout,并通过代码添加了EditText:

    <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" . 如果是这样,则无需进行任何大小调整-在布局文件中设置android:layout_width="fill_parent"并使其在android:visibility="gone"android:visibility="gone"

Then, in the onClickListener on your button, you can call et.setVisible(Visibility.VISIBLE) . 然后,在按钮上的et.setVisible(Visibility.VISIBLE) ,可以调用et.setVisible(Visibility.VISIBLE)

A possible solution: ScaleAnimation. 可能的解决方案: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. 效果也不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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