最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實(shí)現(xiàn)兩張圖片2D翻轉(zhuǎn)動畫效果

 更新時(shí)間:2022年08月22日 08:35:16   作者:碼靈薯  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)兩張圖片2D翻轉(zhuǎn)動畫效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java實(shí)現(xiàn)兩張圖片2D翻轉(zhuǎn)動畫的具體代碼,供大家參考,具體內(nèi)容如下

這可能是簡單的動畫效果吧,但是感覺還挺有意思的。

效果如下

XML代碼如下,很簡單只有兩個imageview

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:id="@+id/framelayout1"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? tools:context="com.example.dreverse.MainActivity" >

? ? <ImageView
? ? ? ? android:id="@+id/imageView1"
? ? ? ? android:layout_width="fill_parent"
? ? ? ? android:layout_height="fill_parent"
? ? ? ? android:src="@drawable/image1" />

? ? <ImageView
? ? ? ? android:id="@+id/imageView2"
? ? ? ? android:layout_width="fill_parent"
? ? ? ? android:layout_height="fill_parent"
? ? ? ? android:src="@drawable/image2" />

</FrameLayout>

java代碼,也挺簡單的

/*the reversing animation of two pictures
?* @author stephenson feng
?* @date 2016-9-4
?* */
package com.example.dreverse;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

public class MainActivity extends Activity {

? ? private ImageView imageview1;
? ? private ImageView imageview2;
? ? //第一個動畫,效果是像翻轉(zhuǎn)似得消失
? ? //第一個參數(shù)和第二個參數(shù)表示在x軸上的變化:從1變?yōu)?。
? ? //第三個參數(shù)和第四個參數(shù)表示在y軸上的變化:從1變?yōu)?,沒有變化。
? ? //第五個參數(shù)和第六個參數(shù)表示在x軸上的變化所參考的位置:RELATIVE_TO_PARENT沿著父級空間,0.5f的中心點(diǎn)。
? ? //第七個參數(shù)和第八個參數(shù)表示在y軸上的變化所參考的位置:含義與x軸類似
? ? private ScaleAnimation sato1=new ScaleAnimation(1, 0, 1, 1,?
? ? ? ? ? ? Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
? ? //第二個動畫,效果是像翻轉(zhuǎn)似得出現(xiàn)
? ? private ScaleAnimation sato2=new ScaleAnimation(0, 1, 1, 1,?
? ? ? ? ? ? Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? //自定義的一個初始化方法
? ? ? ? initImage();
? ? ? ? //主布局使用的是框架布局framelayout,其中只有一個圖片,所以點(diǎn)擊framelayout時(shí)候就翻轉(zhuǎn)圖片
? ? ? ? findViewById(R.id.framelayout1).setOnClickListener(new OnClickListener() {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if (imageview1.isShown()) {//當(dāng)前的圖片是圖片1
? ? ? ? ? ? ? ? ? ? imageview1.startAnimation(sato1);//圖片1翻轉(zhuǎn)式消失
? ? ? ? ? ? ? ? }else {//當(dāng)前圖片是圖片2的話,圖片2就翻轉(zhuǎn)式消失
? ? ? ? ? ? ? ? ? ? imageview2.startAnimation(sato1);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? private void showImage1(){
? ? ? ? imageview1.setVisibility(View.VISIBLE);//圖片1可見
? ? ? ? imageview2.setVisibility(View.INVISIBLE);//圖片2不可見
? ? }
? ? private void showImage2(){
? ? ? ? imageview1.setVisibility(View.INVISIBLE);//圖片1不可見
? ? ? ? imageview2.setVisibility(View.VISIBLE);//圖片2可見
? ? }
? ? private void initImage(){
? ? ? ? imageview1 = (ImageView) findViewById(R.id.imageView1);
? ? ? ? imageview2 = (ImageView) findViewById(R.id.imageView2);
? ? ? ? showImage1();//默認(rèn)顯示圖片1
? ? ? ? sato1.setDuration(1000);//給動畫設(shè)置執(zhí)行時(shí)間
? ? ? ? sato2.setDuration(1000);
? ? ? ? //給動畫1設(shè)置時(shí)間監(jiān)聽器,因?yàn)橐男Ч牵涸趧赢嬕唤Y(jié)束時(shí)立即開始動畫2
? ? ? ? sato1.setAnimationListener(new AnimationListener() {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationStart(Animation animation) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? }

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationRepeat(Animation animation) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? }
? ? ? ? ? ? //動畫結(jié)束的時(shí)候執(zhí)行的方法 ? ? ? ? ?
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationEnd(Animation animation) {
? ? ? ? ? ? ? ? //如果當(dāng)前圖片是圖片1
? ? ? ? ? ? ? ? if (imageview1.getVisibility()==View.VISIBLE) {
? ? ? ? ? ? ? ? ? ? //把圖片1的動畫設(shè)置為空,現(xiàn)在圖片1的不需要了。也方便下一次設(shè)置動畫
? ? ? ? ? ? ? ? ? ? imageview1.setAnimation(null);
? ? ? ? ? ? ? ? ? ? imageview2.startAnimation(sato2);//圖片2按照動畫2出場 ??
? ? ? ? ? ? ? ? ? ? showImage2();//動畫播完了后,把圖片2顯示出來
? ? ? ? ? ? ? ? }else {//如果當(dāng)前的圖片是圖片2,圖片1就翻轉(zhuǎn)式的出現(xiàn)
? ? ? ? ? ? ? ? ? ? imageview2.setAnimation(null);
? ? ? ? ? ? ? ? ? ? imageview1.startAnimation(sato2);
? ? ? ? ? ? ? ? ? ? showImage1();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

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

相關(guān)文章

最新評論

泰和县| 大洼县| 双峰县| 新竹县| 江达县| 闽侯县| 龙岩市| 阜新| 江西省| 平潭县| 昂仁县| 中西区| 惠安县| 尚志市| 泰宁县| 乐清市| 南澳县| 阆中市| 四川省| 安宁市| 宾川县| 偏关县| 开江县| 德惠市| 同仁县| 南宁市| 石棉县| 雅安市| 房产| 临泽县| 札达县| 浦江县| 江孜县| 泸西县| 神木县| 京山县| 新河县| 泸州市| 泾阳县| 泗阳县| 浦县|