Android scale animation on view

前端 未结 7 1023
轮回少年
轮回少年 2020-11-28 04:10

I want to use ScaleAnimation (programmatically not in xml) to change height to view from 0 to 60% of parent height. Width of view is constant and is 50px. View is empty onl

7条回答
  •  Happy的楠姐
    2020-11-28 04:38

    In XML, this what I use for achieving the same result. May be this is more intuitive.

    scale_up.xml

    
    
    
    
    
    
    

    scale_down.xml

    
    
    
    
    
    
    

    See the animation on the X axis is from 1.0 -> 1.0 which means you don't have any scaling up in that direction and stays at the full width while, on the Y axis you get 0.0 -> 1.0 scaling, as shown in the graphic in the question. Hope this helps someone.

    Some might want to know the java code as we see one requested.

    Place the animation files in anim folder and then load and set animation files something like.

    Animation scaleDown = AnimationUtils.loadAnimation(youContext, R.anim.scale_down);
    ImagView v = findViewById(R.id.your_image_view);
    v.startAnimation(scaleDown);
    

提交回复
热议问题