100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android淡入淡出动画_在Android中淡入动画示例

android淡入淡出动画_在Android中淡入动画示例

时间:2023-08-04 03:57:06

相关推荐

android淡入淡出动画_在Android中淡入动画示例

android淡入淡出动画

1) XML File: activity_main

1)XML文件:activity_main

<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="/apk/res/android"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.faraz.Animation_Example.MainActivity"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"></LinearLayout><ViewFlipperandroid:id="@+id/backgroundViewFlipper1"android:layout_width="fill_parent"android:layout_height="fill_parent"><ImageViewandroid:id="@+id/backgroundImageView1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/tiger_2"android:adjustViewBounds="true" /><ImageViewandroid:id="@+id/backgroundImageView2"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/tigertiger"android:adjustViewBounds="true"/><ImageViewandroid:id="@+id/backgroundImageView3"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/white2"android:adjustViewBounds="true"/><ImageViewandroid:id="@+id/backgroundImageView4"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/white4"android:adjustViewBounds="true"/><ImageViewandroid:id="@+id/backgroundImageView5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:scaleType="centerCrop"android:src="@drawable/white_tiger_copy"/><ImageViewandroid:id="@+id/backgroundImageView6"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/tiger" android:adjustViewBounds="true"/><ImageViewandroid:id="@+id/backgroundImageView7"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/tigress"android:adjustViewBounds="true"/><ImageViewandroid:id="@+id/backgroundImageView8"android:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="centerCrop"android:src="@drawable/wildcat"android:adjustViewBounds="true"/></ViewFlipper></android.support.constraint.ConstraintLayout>

In the above code in every ImageView you will find android:src="@drawable/tigress" shows an error. Actually the error is concern about image/images. The particular images I use in this article will not be there in your computer, so first you have to copy your own images from your computer to ‘drawable’ folder in android studio and also write the same spelling of image in android:src="@drawable/your_image_name".

在每个ImageView中的上述代码中,您会发现android:src =“ @ drawable / tigress”显示错误。 实际上,该错误与图像有关。 我在本文中使用的特定图像不会在您的计算机中出现,因此首先您必须将计算机中的图像复制到android studio中的“ drawable”文件夹中,并且还要在android:src =“中写入相同的图像拼写: @ drawable / your_image_name” 。

Here in ‘drawable’ folder you should copy your images which you would like to see in animation. As you copy your images, in drawble, red color will change in green color android:src="@drawable/your_image_name ". Error removes.

在“可绘制”文件夹中,您应该复制想要在动画中看到的图像。 复制图像时,在drawble中,红色将变为绿色android:src =“ @ drawable / your_image_name” 。 错误消除。

2) File: MainActivity.java

2)文件:MainActivity.java

package com.example.faraz.Animation_Example;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.ViewFlipper;public class MainActivity extends AppCompatActivity {Animation fade_in, fade_out;ViewFlipper viewFlipper;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);viewFlipper= (ViewFlipper) this.findViewById(R.id.backgroundViewFlipper1);fade_in= AnimationUtils.loadAnimation(this,android.R.anim.fade_in);fade_out=AnimationUtils.loadAnimation(this,android.R.anim.fade_out);viewFlipper.setAnimation(fade_in);viewFlipper.setAnimation(fade_out);viewFlipper.setAutoStart(true);viewFlipper.setFlipInterval(5000);viewFlipper.startFlipping();}}

In android, there are many possible ways to make ‘fade in’ animation and here I used alpha tag and it is one the easy and most used ways of making animation. For the fade in animation using alpha tag you have to create an anim folder in your res directory.

在android中,有很多方法可以制作“淡入”动画,在这里我使用了alpha标记,这是制作动画最简单且最常用的方法之一。 对于使用alpha标签的淡入动画,您必须在res目录中创建一个anim文件夹。

After creating anim folder in res/ directory and also create fadein.xml file in res/anim/ directory and place the following content.

在res /目录中创建anim文件夹,并在res / anim /目录中创建fadein.xml文件后,放置以下内容。

3) XML File: fadein.xml

3)XML文件:fadein.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="/apk/res/android"><alphaandroid:duration="2000"android:fromAlpha="1.0"android:toAlpha="0.0"android:interpolator="@android:anim/accelerate_interpolator"/></set>

Output:After executing your code on your device/virtual device, you get animated images.

输出:在设备/虚拟设备上执行代码后,您将获得动画图像。

翻译自: /android/fade-in-animation-example.aspx

android淡入淡出动画

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。