欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Animation之TranslateAnimation(平移動畫)

 更新時間:2017年09月28日 09:27:29   作者:長彬  
這篇文章主要為大家詳細介紹了Animation之TranslateAnimation平移動畫,具有一定的參考價值,感興趣的小伙伴們可以參考一下

TranslateAnimation(平移動畫)的意思無非就是一張圖片或其他從一個位置到達另外一個位置。直接代碼分析,相關重要屬性參數(shù)解釋都在代碼中。

1、首先編寫main.xml文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
  android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
  android:paddingRight="@dimen/activity_horizontal_margin" 
  android:paddingTop="@dimen/activity_vertical_margin" 
  android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

  <ImageView 
    android:id="@+id/image" 
    android:text="@string/hello_world" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/car_one1"/> 

</RelativeLayout> 

2、接下來編寫MainActivity.java文件。

package com.example.dell.bitmapproject; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationSet; 
import android.view.animation.TranslateAnimation; 
import android.widget.ImageView; 

public class MainActivity extends AppCompatActivity { 
  private ImageView image; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    image =(ImageView)findViewById(R.id.image); 
    image.setOnClickListener(new OnClickListenerImpl()); 
  } 
  private class OnClickListenerImpl implements View.OnClickListener { 
    @Override 
    public void onClick(View v) { 
      /* 
        AnimationSet相當于一個動畫的集合,true表示使用Animation的interpolator 
        false則是使用自己的。 
        Interpolator 被用來修飾動畫效果,定義動畫的變化率,可以使存在的動畫效果 
        accelerated(加速),decelerated(減速),repeated(重復),bounced(彈跳)等。 
       */ 

      AnimationSet animationSet = new AnimationSet(true); 
      /* 
          Animation還有幾個方法 
          setFillAfter(boolean fillAfter) 
          如果fillAfter的值為真的話,動畫結束后,控件停留在執(zhí)行后的狀態(tài) 
          setFillBefore(boolean fillBefore) 
          如果fillBefore的值為真的話,動畫結束后,控件停留在動畫開始的狀態(tài) 
          setStartOffset(long startOffset) 
          設置動畫控件執(zhí)行動畫之前等待的時間 
          setRepeatCount(int repeatCount) 
          設置動畫重復執(zhí)行的次數(shù) 
       */ 
      TranslateAnimation translateAnimation = new TranslateAnimation( 
          //X軸初始位置 
          Animation.RELATIVE_TO_SELF, 0.0f, 
          //X軸移動的結束位置 
          Animation.RELATIVE_TO_SELF,0.5f, 
          //y軸開始位置 
          Animation.RELATIVE_TO_SELF,0.0f, 
          //y軸移動后的結束位置 
          Animation.RELATIVE_TO_SELF,1.5f); 

      //3秒完成動畫 
      translateAnimation.setDuration(2000); 
      //如果fillAfter的值為真的話,動畫結束后,控件停留在執(zhí)行后的狀態(tài) 
      animationSet.setFillAfter(true); 
      //將AlphaAnimation這個已經(jīng)設置好的動畫添加到 AnimationSet中 
      animationSet.addAnimation(translateAnimation); 
      //啟動動畫 
      MainActivity.this.image.startAnimation(animationSet); 

    } 
  } 
} 

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android對EditTex的圖片實現(xiàn)監(jiān)聽

    Android對EditTex的圖片實現(xiàn)監(jiān)聽

    這篇文章主要為大家詳細介紹了Android如何對EditTex的圖片實現(xiàn)監(jiān)聽,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android實現(xiàn)簡單計算器界面

    Android實現(xiàn)簡單計算器界面

    這篇文章主要為大家詳細介紹了Android實現(xiàn)簡單計算器界面,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • Android客戶端實現(xiàn)圖片輪播控件

    Android客戶端實現(xiàn)圖片輪播控件

    這篇文章主要為大家詳細介紹了Android客戶端實現(xiàn)圖片輪播控件,并且和大家一起制作圖片輪播控件,分享給大家,感興趣的朋友可以參考一下
    2016-04-04
  • Android中去掉標題欄的幾種方法(三種)

    Android中去掉標題欄的幾種方法(三種)

    本文給大家?guī)砹巳Nandroid去掉標題欄的方法,都非常不錯,對android 去掉標題欄的方法感興趣的朋友一起通過本文學習吧
    2016-08-08
  • Android開發(fā)筆記之Intent初級學習教程

    Android開發(fā)筆記之Intent初級學習教程

    這篇文章主要介紹了Android開發(fā)筆記之Intent初級學習,較為詳細的分析了Android Intent項目的建立,功能實現(xiàn)及Intent使用技巧,需要的朋友可以參考下
    2016-02-02
  • Android仿微信語音消息的錄制和播放功能

    Android仿微信語音消息的錄制和播放功能

    這篇文章主要介紹了Android仿微信語音消息的錄制和播放功能,需要的朋友可以參考下
    2017-09-09
  • Android利用HelloChart繪制曲線

    Android利用HelloChart繪制曲線

    這篇文章主要為大家詳細介紹了Android利用HelloChart繪制曲線,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Android實現(xiàn)平滑翻動效果

    Android實現(xiàn)平滑翻動效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)平滑翻動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android中利用C++處理Bitmap對象的實現(xiàn)方法

    Android中利用C++處理Bitmap對象的實現(xiàn)方法

    下面小編就為大家?guī)硪黄狝ndroid中利用C++處理Bitmap對象的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • Android 圖片選擇詳解及實例代碼

    Android 圖片選擇詳解及實例代碼

    這篇文章主要介紹了 Android 圖片選擇詳解及實例代碼的相關資料,需要的朋友可以參考下
    2016-12-12

最新評論