SoFunction
Updated on 2025-04-04

Example of Android control Tween animation (tween animation) implementation method

This article describes the implementation method of Android control Tween animation (tween animation). Share it for your reference, as follows:

Tween animation in Android animation: It is to continuously change the image of the control object to produce animation effects such as rotation, translation, scaling and gradient.

/**
  * Control Tween animation
  *
  * @description:
  * @author ldm
  * @date 2016-6-22 5:26:24 pm
  */
public class TweenActivity extends Activity {
  private SeekBar seekBarX;// Drag the bar control  private SeekBar seekBarY;
  private SeekBar scaleSeekBarX;
  private SeekBar scaleSeekBarY;
  private SeekBar rotationSeekBarX;
  private SeekBar rotationSeekBarY;
  private SeekBar rotationSeekBarZ;
  private Button button;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView(.activity_tween);
    initViews();
    initEvents();
  }
  /**
    *
    * @description: Initialize the control
    * @author ldm
    * @date 2016-6-22 5:26:26 pm
    */
  private void initViews() {
    button = (Button) findViewById();
    seekBarX = (SeekBar) findViewById();
    (400);
    seekBarY = (SeekBar) findViewById();
    (800);
    scaleSeekBarX = (SeekBar) findViewById();
    (50);
    (10);
    scaleSeekBarY = (SeekBar) findViewById();
    (50);
    (10);
    rotationSeekBarX = (SeekBar) findViewById();
    (360);
    rotationSeekBarY = (SeekBar) findViewById();
    (360);
    rotationSeekBarZ = (SeekBar) findViewById();
    (360);
  }
  /**
    *
    * @description: Control settings listen events
    * @author ldm
    * @date 2016-6-22 5:26:26 pm
    */
  private void initEvents() {
    // The button X direction is flat-moving    (new () {
      public void onStopTrackingTouch(SeekBar seekBar) {
      }
      public void onStartTrackingTouch(SeekBar seekBar) {
      }
      public void onProgressChanged(SeekBar seekBar, int progress,
          boolean fromUser) {
        // Translation in X direction        ((float) progress);
      }
    });
    // The button is flat-moving in the Y direction    (new () {
      public void onStopTrackingTouch(SeekBar seekBar) {
      }
      public void onStartTrackingTouch(SeekBar seekBar) {
      }
      public void onProgressChanged(SeekBar seekBar, int progress,
          boolean fromUser) {
        // Translation in Y direction        ((float) progress);
      }
    });
    // button X direction zoom animation    scaleSeekBarX
        .setOnSeekBarChangeListener(new () {
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
          public void onStartTrackingTouch(SeekBar seekBar) {
          }
          public void onProgressChanged(SeekBar seekBar,
              int progress, boolean fromUser) {
            // X-direction zoom            ((float) progress / 10f);
          }
        });
    // button Y direction zoom animation    scaleSeekBarY
        .setOnSeekBarChangeListener(new () {
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
          public void onStartTrackingTouch(SeekBar seekBar) {
          }
          public void onProgressChanged(SeekBar seekBar,
              int progress, boolean fromUser) {
            // Y direction zoom            ((float) progress / 10f);
          }
        });
    // Button X direction rotation animation    rotationSeekBarX
        .setOnSeekBarChangeListener(new () {
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
          public void onStartTrackingTouch(SeekBar seekBar) {
          }
          public void onProgressChanged(SeekBar seekBar,
              int progress, boolean fromUser) {
            // Rotate in the X direction            ((float) progress);
          }
        });
    // Button Y direction rotation animation    rotationSeekBarY
        .setOnSeekBarChangeListener(new () {
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
          public void onStartTrackingTouch(SeekBar seekBar) {
          }
          public void onProgressChanged(SeekBar seekBar,
              int progress, boolean fromUser) {
            // Rotate in Y direction            ((float) progress);
          }
        });
    // button Z direction rotation animation    rotationSeekBarZ
        .setOnSeekBarChangeListener(new () {
          public void onStopTrackingTouch(SeekBar seekBar) {
          }
          public void onStartTrackingTouch(SeekBar seekBar) {
          }
          public void onProgressChanged(SeekBar seekBar,
              int progress, boolean fromUser) {
            // Set rotation            ((float) progress);
          }
        });
  }
}

Layout file.activity_tween

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro
  android:
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:splitMotionEvents="true" >
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dip"
    android:orientation="horizontal"
    android:splitMotionEvents="true" >
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="5dip"
      android:paddingRight="5dip"
      android:text="TX"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="15dip"
      android:paddingRight="5dip"
      android:text="TY"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
  </LinearLayout>
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dip"
    android:orientation="horizontal"
    android:splitMotionEvents="true" >
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="5dip"
      android:paddingRight="5dip"
      android:text="SX"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="15dip"
      android:paddingRight="5dip"
      android:text="SY"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
  </LinearLayout>
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dip"
    android:orientation="horizontal"
    android:splitMotionEvents="true" >
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="5dip"
      android:paddingRight="5dip"
      android:text="X"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="15dip"
      android:paddingRight="5dip"
      android:text="Y"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingLeft="15dip"
      android:paddingRight="5dip"
      android:text="Z"
      android:textStyle="bold" />
    <SeekBar
      android:
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="horizontal" />
  </LinearLayout>
  <Button
    android:
    android:layout_width="200dip"
    android:layout_height="150dip"
    android:layout_marginLeft="50dip"
    android:layout_marginTop="50dip"
    android:text="Rotating Button" />
</LinearLayout>

For more information about Android related content, please check out the topic of this site:Android development animation skills summary》、《Android development introduction and advanced tutorial》、《Android View View Tips Summary》、《Android programming activity operation skills summary》、《Android file operation skills summary》、《Android resource operation skills summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.