Este artigo descreve o código de exemplo para Java implementar a animação do quadro. Compartilhe -o para sua referência, como segue:
1. Diagrama de reprodução
2. Código breve para animação do quadro
ImageView privado bganimview; Private Animation Drawable Manimation Drawable; // inicialize manimationdrawable = new animationDrawable (); bganimview = new ImageView (mcOntext); bganimview.setBackgroundDrawable (GetanimationDrawable (ManimationDrawable); params = new Framelayout.LayoutParams (ViewGroup.LayoutParams.Wrap_Content, ViewGroup.LayoutParams.wrap_content); params.topMargin = util.div (176 + 58); params.gravity = gravity.center_horizontal; addView (bganimview, params); Private AnimationDrawable GetanimationDrawable (AnimationDrawable ManimationDrawable) {int duração = 50; manimationdrawable.addframe (mcOntext.getResources (). getDrawable (r.Drawable.Loading1), duração); manimationdrawable.addframe (mcOntext.getResources (). getDrawable (r.Drawable.Loading2), duração); manimationdrawable.addframe (mcOntext.getResources (). getDrawable (r.Drawable.Loading3), duração); manimationdrawable.setoneshot (false); retornar manimation drawable; } // anime start public void AnimloadingStart () {this.setVisability (View.visible); if (manimationdrawable! = null) {manimationdrawable.start (); }} // anime end public void animLargondingN () {if (manimationdrawable! = Null) {manimationdrawable.stop (); } 3. Extensão:
// X-AXIS Tradução public void animy (int y, int nexty, int duração) {linearInterpolator ll = new linearInterpolator (); // constant-speed objetanimator animator = objectanimator.offloat (yourview, "tradução", 0, 300); // 300 Se for um valor negativo, é traduzido para cima animador.setDuration (duração); animator.setInterpolator (LL); animator.start (); } // y-axis tradução public void animx (int x, int nextX, int duração) {linearInterpolator ll = new linearInterpolator (); Objectanimator animator = objectanimator.offloat (yourview, "traduçãox", x, nextX); animator.setDuration (duração); animator.setInterpolator (LL); animator.start (); } // compressão solar 0,5 vezes linearInterpolator ll = new linearInterpolator (); // scaleanimation estático scaleanimation = new scaleanimation (1, 1, 1, 0,5f); // inadimplência de (0,0) scaleanimation.setdaturation (500); scaleanimation.setInterpolator (LL); scaleanimation.setFillafter (true); ChartView.Startanimation (Scaleanimation); // compressão horizontal 0,5 vezes linearInterpolator ll = new linearInterpolator (); Scaleanimation scaleanimation = nova scaleanimation (1, 0,5f, 1, 1); // padrão de (0,0) scaleanimation.setDuration (500); scaleanimation.setInterpolator (LL); scaleanimation.setFillafter (true); ChartView.Startanimation (Scaleanimation);Clique para abrir o endereço de download do material
O acima é o conteúdo inteiro deste artigo. Espero que o conteúdo deste artigo tenha certo valor de referência para o estudo ou trabalho de todos. Se você tiver alguma dúvida, pode deixar uma mensagem para se comunicar. Obrigado pelo seu apoio ao wulin.com.