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

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

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

本文實例為大家分享了java實現(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的中心點。
? ? //第七個參數(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,其中只有一個圖片,所以點擊framelayout時候就翻轉(zhuǎn)圖片
? ? ? ? findViewById(R.id.framelayout1).setOnClickListener(new OnClickListener() {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if (imageview1.isShown()) {//當前的圖片是圖片1
? ? ? ? ? ? ? ? ? ? imageview1.startAnimation(sato1);//圖片1翻轉(zhuǎn)式消失
? ? ? ? ? ? ? ? }else {//當前圖片是圖片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();//默認顯示圖片1
? ? ? ? sato1.setDuration(1000);//給動畫設(shè)置執(zhí)行時間
? ? ? ? sato2.setDuration(1000);
? ? ? ? //給動畫1設(shè)置時間監(jiān)聽器,因為要的效果是:在動畫一結(jié)束時立即開始動畫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é)束的時候執(zhí)行的方法 ? ? ? ? ?
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAnimationEnd(Animation animation) {
? ? ? ? ? ? ? ? //如果當前圖片是圖片1
? ? ? ? ? ? ? ? if (imageview1.getVisibility()==View.VISIBLE) {
? ? ? ? ? ? ? ? ? ? //把圖片1的動畫設(shè)置為空,現(xiàn)在圖片1的不需要了。也方便下一次設(shè)置動畫
? ? ? ? ? ? ? ? ? ? imageview1.setAnimation(null);
? ? ? ? ? ? ? ? ? ? imageview2.startAnimation(sato2);//圖片2按照動畫2出場 ??
? ? ? ? ? ? ? ? ? ? showImage2();//動畫播完了后,把圖片2顯示出來
? ? ? ? ? ? ? ? }else {//如果當前的圖片是圖片2,圖片1就翻轉(zhuǎn)式的出現(xiàn)
? ? ? ? ? ? ? ? ? ? imageview2.setAnimation(null);
? ? ? ? ? ? ? ? ? ? imageview1.startAnimation(sato2);
? ? ? ? ? ? ? ? ? ? showImage1();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

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

相關(guān)文章

最新評論

井冈山市| 信丰县| 龙州县| 沽源县| 三亚市| 南皮县| 武隆县| 武邑县| 广丰县| 高阳县| 大田县| 大埔县| 邮箱| 平湖市| 孝义市| 鸡西市| 郁南县| 佛冈县| 泌阳县| 临邑县| 平阴县| 淮安市| 奉化市| 神池县| 英超| 庆城县| 龙州县| 武宁县| 黄冈市| 五台县| 海原县| 名山县| 确山县| 凤阳县| 科尔| 巫山县| 阿拉善左旗| 南投市| 绵竹市| 河西区| 泰安市|