国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android控件Tween動畫(補間動畫)實現方法示例

2019-10-22 18:30:02
字體:
來源:轉載
供稿:網友

本文實例講述了Android控件Tween動畫(補間動畫)實現方法。分享給大家供大家參考,具體如下:

Android動畫中的Tween動畫:是把控件對象不斷的進行圖像變化來產生旋轉、平移、放縮和漸變等動畫效果。

/** * 控件Tween動畫 *  * @description: * @author ldm * @date 2016-6-22 下午5:26:24 */public class TweenActivity extends Activity {  private SeekBar seekBarX;// 拖動條控件  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) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_tween);    initViews();    initEvents();  }  /**   *    * @description:初始化控件   * @author ldm   * @date 2016-6-22 下午5:26:26   */  private void initViews() {    button = (Button) findViewById(R.id.button);    seekBarX = (SeekBar) findViewById(R.id.translationX);    seekBarX.setMax(400);    seekBarY = (SeekBar) findViewById(R.id.translationY);    seekBarY.setMax(800);    scaleSeekBarX = (SeekBar) findViewById(R.id.scaleX);    scaleSeekBarX.setMax(50);    scaleSeekBarX.setProgress(10);    scaleSeekBarY = (SeekBar) findViewById(R.id.scaleY);    scaleSeekBarY.setMax(50);    scaleSeekBarY.setProgress(10);    rotationSeekBarX = (SeekBar) findViewById(R.id.rotationX);    rotationSeekBarX.setMax(360);    rotationSeekBarY = (SeekBar) findViewById(R.id.rotationY);    rotationSeekBarY.setMax(360);    rotationSeekBarZ = (SeekBar) findViewById(R.id.rotationZ);    rotationSeekBarZ.setMax(360);  }  /**   *    * @description:控件設置監聽事件   * @author ldm   * @date 2016-6-22 下午5:26:26   */  private void initEvents() {    // 按鈕X方向平移動畫    seekBarX.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {      public void onStopTrackingTouch(SeekBar seekBar) {      }      public void onStartTrackingTouch(SeekBar seekBar) {      }      public void onProgressChanged(SeekBar seekBar, int progress,          boolean fromUser) {        // X方向平移        button.setTranslationX((float) progress);      }    });    // 按鈕Y方向平移動畫    seekBarY.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {      public void onStopTrackingTouch(SeekBar seekBar) {      }      public void onStartTrackingTouch(SeekBar seekBar) {      }      public void onProgressChanged(SeekBar seekBar, int progress,          boolean fromUser) {        // Y方向平移        button.setTranslationY((float) progress);      }    });    // 按鈕X方向縮放動畫    scaleSeekBarX        .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {          public void onStopTrackingTouch(SeekBar seekBar) {          }          public void onStartTrackingTouch(SeekBar seekBar) {          }          public void onProgressChanged(SeekBar seekBar,              int progress, boolean fromUser) {            // X方向縮放            button.setScaleX((float) progress / 10f);          }        });    // 按鈕Y方向縮放動畫    scaleSeekBarY        .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {          public void onStopTrackingTouch(SeekBar seekBar) {          }          public void onStartTrackingTouch(SeekBar seekBar) {          }          public void onProgressChanged(SeekBar seekBar,              int progress, boolean fromUser) {            // Y方向縮放            button.setScaleY((float) progress / 10f);          }        });    // 按鈕X方向旋轉動畫    rotationSeekBarX        .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {          public void onStopTrackingTouch(SeekBar seekBar) {          }          public void onStartTrackingTouch(SeekBar seekBar) {          }          public void onProgressChanged(SeekBar seekBar,              int progress, boolean fromUser) {            // X方向旋轉            button.setRotationX((float) progress);          }        });    // 按鈕Y方向旋轉動畫    rotationSeekBarY        .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {          public void onStopTrackingTouch(SeekBar seekBar) {          }          public void onStartTrackingTouch(SeekBar seekBar) {          }          public void onProgressChanged(SeekBar seekBar,              int progress, boolean fromUser) {            // Y方向旋轉            button.setRotationY((float) progress);          }        });    // 按鈕Z方向旋轉動畫    rotationSeekBarZ        .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {          public void onStopTrackingTouch(SeekBar seekBar) {          }          public void onStartTrackingTouch(SeekBar seekBar) {          }          public void onProgressChanged(SeekBar seekBar,              int progress, boolean fromUser) {            // 設置旋轉            button.setRotation((float) progress);          }        });  }}

布局文件R.layout.activity_tween

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/container"  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:id="@+id/translationX"      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:id="@+id/translationY"      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:id="@+id/scaleX"      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:id="@+id/scaleY"      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:id="@+id/rotationX"      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:id="@+id/rotationY"      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:id="@+id/rotationZ"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_weight="1"      android:orientation="horizontal" />  </LinearLayout>  <Button    android:id="@+id/rotatingButton"    android:layout_width="200dip"    android:layout_height="150dip"    android:layout_marginLeft="50dip"    android:layout_marginTop="50dip"    android:text="Rotating Button" /></LinearLayout>

希望本文所述對大家Android程序設計有所幫助。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 繁峙县| 普定县| 博客| 徐水县| 宁武县| 霍林郭勒市| 军事| 宣恩县| 景宁| 扶绥县| 长治县| 庆城县| 扶风县| 宁海县| 赣州市| 隆回县| 上高县| 阆中市| 灌阳县| 白河县| 长寿区| 堆龙德庆县| 泰州市| 寻甸| 蒙山县| 吉隆县| 房产| 龙井市| 峨山| 井陉县| 封丘县| 牙克石市| 普陀区| 和田县| 洛南县| 鄂伦春自治旗| 横山县| 扶风县| 石台县| 西畴县| 郁南县|