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="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.faraz.Animation_Example.MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<ViewFlipper
android:id="@+id/backgroundViewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/backgroundImageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/tiger_2"
android:adjustViewBounds="true" />
<ImageView
android:id="@+id/backgroundImageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/tigertiger"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/backgroundImageView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/white2"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/backgroundImageView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/white4"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/backgroundImageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/white_tiger_copy"
/>
<ImageView
android:id="@+id/backgroundImageView6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/tiger" 
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/backgroundImageView7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/tigress"
android:adjustViewBounds="true"/>
<ImageView
android: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” 。

Android - Fade In Example 0

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;
@Override
protected 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文件夾。

Android - Fade In Example 1

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="http://schemas.android.com/apk/res/android">
<alpha
android: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.

輸出:在設備/虛擬設備上執行代碼后,您將獲得動畫圖像。

翻譯自: https://www.includehelp.com/android/fade-in-animation-example.aspx

android淡入淡出動畫

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377837.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377837.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377837.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[慢查優化]聯表查詢注意誰是驅動表 你搞不清楚誰join誰更好時請放手讓mysql自行判定...

寫在前面的話&#xff1a; 不要求每個人一定理解 聯表查詢(join/left join/inner join等)時的mysql運算過程&#xff1b; 不要求每個人一定知道線上&#xff08;現在或未來&#xff09;哪張表數據量大&#xff0c;哪張表數據量小&#xff1b; 但把mysql客戶端&#xff08;如SQL…

四、梯度下降歸一化操作

一、歸一化 Ⅰ什么是歸一化&#xff1f; 答&#xff1a;其實就是把數據歸一到0-1之間&#xff0c;也就是縮放。 常用的歸一化操作是最大最小值歸一化&#xff0c;公式如下&#xff1a; 例如&#xff1a;1&#xff0c;3&#xff0c;5&#xff0c;7&#xff0c;9&#xff0c;10…

[轉帖][強烈推薦]網頁表格(Table/GridView)標題欄和列凍結(跨瀏覽器兼容)

GridView的標題欄、列凍結效果(跨瀏覽器版) 本文來源&#xff1a;http://blog.darkthread.net/blogs/darkthreadtw/archive/2009/02/18/supertable-plugin-for-jquery.aspx 稍早發表了GridView 的標題列凍結效果&#xff0c;足以滿足工作上的需求&#xff0c;不過存在兩個缺點:…

psu是什么電腦配件_PSU的完整形式是什么?

psu是什么電腦配件PSU&#xff1a;電源部門/公共部門事業 (PSU: Power Supply Unit / Public Sector Undertaking) 1)PSU&#xff1a;電源設備 (1) PSU: Power Supply Unit) PSU is an abbreviation of the "Power Supply Unit". PSU是“電源設備”的縮寫 。 It is a…

【C++grammar】斷言與表達式常量

目錄1、常量表達式和constexpr關鍵字2、斷言與C11的靜態斷言1.1. assert : C語言的宏(Macro)&#xff0c;運行時檢測。1.2. assert()依賴于NDEBUG 宏1.3. assert 幫助調試解決邏輯bug &#xff08;部分替代“斷點/單步調試”&#xff09;2.1static_assert (C11的靜態斷言 )2.2.…

一些又用的國內著名期刊

記&#xff1a; 電子學報、電子與信息學報、圖像圖形學報、自動化學報、計算機學報、軟件學報、計算機研究與發展。轉載于:https://www.cnblogs.com/nanyangzp/p/3322244.html

一、Arduino UNO R3將數據上傳至云平臺

一、準備工作 ①ESP12E Shield ②Arduino UNO R3開發板 ③把ESP12E Shield安裝到Arduino UNO R3開發板上 ④登錄物聯網平臺注冊個賬號&#xff0c;到時候需要使用。 ⑤記錄下來你的Uid和key到時候會用到 ⑥創建個設備&#xff0c;用于測試 ⑦beyondyanyu為設備名&…

怎樣做一個快樂的ASP.NET程序員

首先我想解釋一下標題中兩個關鍵字: "快樂", "ASP.NET程序員". 有的人想成為一個"杰出"的程序員, 或者"資深"的程序員, 簡單來說就是"大牛"級的人物 -- 但是本文不是針對此種發展方向不是說我不鼓勵大家朝這方向走, 而是對我…

__eq___C ++'and_eq'關鍵字和示例

__eq__"and_eq" is an inbuilt keyword that has been around since at least C98. It is an alternative to & (Bitwise AND Assignment) operator and it mostly uses for bit manipulations. “ and_eq”是一個內置關鍵字&#xff0c;至少從C 98起就存在。 它…

leetcode 93. 復原IP地址 思考分析

題目 給定一個只包含數字的字符串&#xff0c;復原它并返回所有可能的 IP 地址格式。 有效的 IP 地址 正好由四個整數&#xff08;每個整數位于 0 到 255之間組成&#xff0c;且不能含有前導 0&#xff09;&#xff0c;整數之間用 ‘.’ 分隔。 例如&#xff1a;“0.1.2.201” …

二、通過云平臺反向控制Arduino UNO R3

該篇博文是在第一篇博文(一、Arduino UNO R3將數據上傳至云平臺)的基礎上進行的 一、云平臺發送指令反向控制Arduino UNO R3 ESP12E Shield開關都推到OFF&#xff08;要不然下載會報錯&#xff09;&#xff0c;往Arduino UNO R3開發板上下載下面的代碼 這段代碼進行測試要點&…

使用MSBuild編譯FsLex項目

FsLex FsYacc微軟本身也提供了一個項目模板。但是這個項目模板是lex和yacc文件均包含。我想只適用lex&#xff0c;但是如果每次使用命令行也覺得不夠方便&#xff0c;于是還是研究了一番MsBuild的使用。 使用msbuild hellp.fsproj /v:d 可以查看整個msbuild的流程&#xff0c;非…

Python字符串格式:%vs.format

Often the string formatters in python are referred to as old style and new style. The old-style is % and .format is known as the new style. python中的字符串格式化程序通常被稱為舊樣式和新樣式。 舊樣式為&#xff05; &#xff0c;. format被稱為新樣式。 Simple…

【C++grammar】代理構造、不可變對象、靜態成員

目錄1、Delegation Constructor&#xff08;代理構造&#xff09;1. What is delegating constructor? (什么是代理構造/委托構造)2. Avoiding recursive calls of target constructors (避免遞歸調用目標ctor)3. 委托構造的好處2、不可變對象和類1、如何讓類成為“不可變類”…

paip.最新的c++ qt5.1.1環境搭建跟hello world

paip.最新的c qt5.1.1環境搭建跟hello world 作者Attilax &#xff0c; EMAIL:1466519819qq.com 來源&#xff1a;attilax的專欄 地址&#xff1a;http://blog.csdn.net/attilax 有一段時間沒接觸c了...今天下載新的qt下來研究一番.. qt的環境搭建有eclipseqtdtmingwqtl…

RFID模塊+WIFI模塊+振動傳感器+有源蜂鳴器+舵機+Arduino UNO R3所構成的門禁系統模塊

該系統模塊主要由RFID模塊WIFI模塊振動傳感器有源蜂鳴器舵機Arduino UNO R3組成的門禁系統模塊。這里使用舵機充當門鎖&#xff0c;用戶可以刷卡開門&#xff0c;也可以通過APP控制舵機狀態達到開門的效果。若有不法分子想要強行進入室內&#xff0c;對門進行撞擊或者人為的破壞…

PushManager

http://suchandalex.googlecode.com/svn/trunk/beOui/beWe/client/Classes/PushNotificationManager.m轉載于:https://www.cnblogs.com/vincent-lu/archive/2012/01/18/2325740.html

krsort_PHP krsort()函數與示例

krsortPHP krsort()函數 (PHP krsort() function) krsort() function is used to sort an associative array in descending order based on the keys, as we know that an associative array contains keys and values, this method sorts an array according to the keys. kr…

ESP12E Shield+Arduino UNO R3開發板+DHT11溫濕度模塊+雙色LED燈+有源蜂鳴器+光敏電阻模塊+I2CLCD1602液晶顯示器所構成的室內檢測系統

室內檢測系統由ESP12E ShieldArduino UNO R3開發板DHT11溫濕度模塊雙色LED燈有源蜂鳴器光敏電阻模塊I2CLCD1602液晶顯示器所構成。DHT11溫濕度模塊獲取室內溫濕度數據通過I2CLCD1602液晶顯示器進行顯示&#xff0c;另一方面通過ESP12E Shield將數據上傳至云平臺。光敏電阻進行捕…

輸入輸出函數:

一、printf函數&#xff1a;     printf("Hello World!\n");     printf("My age is %d\n",26);     int age 17;     printf("My age is %d\n",age);  %d 或 %i: 帶符號 十進制整數。   %o:不帶符號 八進制整數。   %x:…