如何扩大与动画布局的高度? [英] How to expand a layout height with animation?

查看:93
本文介绍了如何扩大与动画布局的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到一个很好的例子,如何做到这一点。

I couldn't find a good example for how to do this.

我有一个RelativeLayout的设置x高。

I have a RelativeLayout set with x height.

我想添加一个按钮,扩展高度X + Y的高度。

I want to add a button which expands the height to x+y height.

有人可以参考我一个很好的例子,对如何以编程方式做到这一点?

can someone refer me to a good example on how to do it programmatically?

推荐答案

请检查下面编辑后的新的答案如下。但在这里,你需要知道确切的新的高度。

Please check below new edited answer as below. But here you need to know the exact new height.

public class layout_animation extends Activity 
{
RelativeLayout ril1;
    /** Called when the activity is first created. */
Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main2);
            ril1=(RelativeLayout)findViewById(R.id.relativeLayout1);
            btn=new Button(this);
            btn.setWidth(100);
            btn.setHeight(200);
            btn.setText("Button");
            actualHeight=210;
            ani  a=new ani();
            a.setDuration(2000);
            ril1.startAnimation(a);
    }
    int initialHeight;
    int actualHeight;
    class ani extends Animation
    {

        public ani()
        {

        }
          @Override
          protected void applyTransformation(float interpolatedTime, Transformation t) {
              int newHeight;

              newHeight = (int)(initialHeight * interpolatedTime);

                ril1.removeAllViews();
                btn.setWidth(100);
                btn.setHeight(300);
                btn.setText("as");
                ril1.addView(btn);             
                ril1.getLayoutParams().height = newHeight;
                ril1.requestLayout();

          }

          @Override
          public void initialize(int width, int height, int parentWidth, int parentHeight) {
              super.initialize(width, height, parentWidth, parentHeight);
              initialHeight = actualHeight;

          }

          @Override
          public boolean willChangeBounds() {
              return true;
          }
      };
}

这篇关于如何扩大与动画布局的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆