How to programmatically animate an ImageView

前端 未结 3 1002
天命终不由人
天命终不由人 2021-02-14 09:19

I am trying to animate an ImageView when the said image view is clicked.

Specifically I want the size of the ImageView gets bigger (say .20 bigger) and the immediately s

3条回答
  •  爱一瞬间的悲伤
    2021-02-14 10:24

    I created the same animation using kotlin:

    Repo: https://github.com/David-Hackro/Bounce-Animation

    You need create your element and extend of anything (ImageView,Button etc) in my case y created a class named BounceWidget

    Add element in xml

    
    

    Add element programmatically

    val xpp = resources.getXml(R.xml.bouncewidget)
    val attr = Xml.asAttributeSet(xpp)
    val layout : LinearLayout = findViewById(R.id.layout)
    val octocat1 : BounceWidget = BounceWidget(this,attr)
    
    //you can change this values and have default values
    
    //octocat1.id_resource(R.mipmap.bounceimage) // change image --> default : R.mipmap.ic_launcher
    //octocat1.positionX = 1 //position X starting --> default : 0
    //octocat1.positionY = 1 //position Y starting--> default : 0
    //octocat1.velocityX = 1 //Velocity X --> default : 20
    //octocat1.velocityY = 1 //Velocity Y --> default : 15
    
    octocat1.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
    
    layout.addView(octocat1)
    

提交回复
热议问题