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

Android xml實現(xiàn)animation的4種動畫效果實例代碼

 更新時間:2016年05月25日 10:17:44   作者:周森  
在Android應(yīng)用程序,使用動畫效果,能帶給用戶更好的感覺,做動畫可以通過XML或Android代碼來實現(xiàn)。本文給大家介紹Android xml實現(xiàn)animation的4種動畫效果實例代碼,一起看看吧

animation有四種動畫類型:分別為alpha(透明的漸變)、rotate(旋轉(zhuǎn))、scale(尺寸伸縮)、translate(移動),二實現(xiàn)的分發(fā)有兩種,一種是javaCode,另外一種是XML,而我今天要說的是XML實現(xiàn)的方法,個人感覺javaCode的實現(xiàn)方法比xml要簡單,所以有需要的可以自己去找找資料看看。

先給大家展示下效果圖,如果大家感覺還不錯,請繼續(xù)往下閱讀。

下面是我的四個xml文件,分別代表這四種動畫類型。

alpha.xml

COde:

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 漸變透明的動畫效果 -->
<!--fromAlpha 動畫起始透明的 1.0完全不透明
toAlpha 動畫結(jié)束時透明的 0.0完全透明
startOffset 設(shè)置啟動時間
duration 屬性動畫持續(xù)時間
-->
<alpha 
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="500"
android:duration="5000"
/>
</set>

rotate.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 畫面轉(zhuǎn)移旋轉(zhuǎn)動畫效果 -->
<!--
fromDegrees開始角度
toDegrees結(jié)束角度
pivotX設(shè)置旋轉(zhuǎn)時的X軸坐標(biāo)
-->
<rotate 
android:fromDegrees="0"
android:toDegrees="+360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"
/>
</set>

scale.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 漸變尺寸伸縮動畫效果 -->
<!--
fromXScale 起始x軸坐標(biāo)
toXScale 止x軸坐標(biāo)
fromYScale 起始y軸坐標(biāo)
toYScale 止y軸坐標(biāo)
pivotX 設(shè)置旋轉(zhuǎn)時的X軸坐標(biāo)
pivotY 設(shè)置旋轉(zhuǎn)時的Y軸坐標(biāo)
duration 持續(xù)時間
-->
<scale 
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"
/>
</set>

translate.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 畫面轉(zhuǎn)移位置移動動畫效果 -->
<translate 
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="5000" 
/>
</set>

下面是主界面xml的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView 
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="200px"
/>
<ImageView 
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="200px"
/>
<ImageView 
android:id="@+id/image3"
android:layout_width="match_parent"
android:layout_height="200px"
/>
<ImageView 
android:id="@+id/image4"
android:layout_width="match_parent"
android:layout_height="200px"
/>
</LinearLayout>

然后是Activity代碼

public class AnimationDemo extends Activity{
private Animation animation,animation1,animation2,animation3;
private ImageView image1,image2,image3,image4;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.animation);
initView();
}
public void initView()
{
animation=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.rotate);
animation1=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.scale);
animation2=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.alpha);
animation3=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.translate);
image1=(ImageView)findViewById(R.id.image1);
image1.setImageResource(R.drawable.jpeg);
image2=(ImageView)findViewById(R.id.image2);
image2.setImageResource(R.drawable.jpg);
image3=(ImageView)findViewById(R.id.image3);
image3.setImageResource(R.drawable.png);
image4=(ImageView)findViewById(R.id.image4);
image4.setImageResource(R.drawable.gif);
image1.startAnimation(animation);
image2.startAnimation(animation1);
image3.startAnimation(animation2);
image4.startAnimation(animation3);
}
}

好了,就這樣就是先了四種動畫效果,另外還有一個知識點,是動畫里面的速率問題,有需要的可以去上網(wǎng)百度看看吧。


相關(guān)文章

  • Android 實現(xiàn)微信登錄詳解

    Android 實現(xiàn)微信登錄詳解

    本文主要介紹Android 微信登錄分享朋友圈,這里給大家詳細(xì)介紹了Android微信登錄的詳細(xì)流程,有需要的小伙伴可以參考下
    2016-07-07
  • Android Zxing生成二維碼經(jīng)典案例分享

    Android Zxing生成二維碼經(jīng)典案例分享

    這篇文章主要為大家分享了Android Zxing生成二維碼經(jīng)典案例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android實現(xiàn)滑動標(biāo)簽頁

    Android實現(xiàn)滑動標(biāo)簽頁

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)滑動標(biāo)簽頁,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • iOS開發(fā)中TableView類似QQ分組的折疊與展開效果

    iOS開發(fā)中TableView類似QQ分組的折疊與展開效果

    這篇文章主要介紹了iOS開發(fā)中TableView類似QQ分組的折疊與展開效果,其實要做這個效果我先想到的是在tableView中再嵌套多個tableView。下面通過本文給大家分享實現(xiàn)思路,需要的朋友可以參考下
    2016-12-12
  • Android系列---JSON數(shù)據(jù)解析的實例

    Android系列---JSON數(shù)據(jù)解析的實例

    JSON(JavaScript Object Notation)和XML,并稱為客戶端和服務(wù)端交互解決方案的倚天劍和屠龍刀,這篇文章主要介紹了Android系列---JSON數(shù)據(jù)解析的實例,有興趣的可以了解一下。
    2016-11-11
  • Android自定義View繪圖實現(xiàn)漸隱動畫

    Android自定義View繪圖實現(xiàn)漸隱動畫

    這篇文章主要為大家詳細(xì)介紹了Android自定義View繪圖實現(xiàn)漸隱動畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • android實現(xiàn)手寫簽名功能

    android實現(xiàn)手寫簽名功能

    這篇文章主要為大家詳細(xì)介紹了android實現(xiàn)手寫簽名功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android實現(xiàn)彈窗進(jìn)度條效果

    Android實現(xiàn)彈窗進(jìn)度條效果

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)彈窗進(jìn)度條效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android組件之BroadcastReceiver廣播接收者

    Android組件之BroadcastReceiver廣播接收者

    這篇文章主要為大家介紹了Android組件之BroadcastReceiver廣播接收者實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • Android開發(fā)筆記之:Handler Runnable與Thread的區(qū)別詳解

    Android開發(fā)筆記之:Handler Runnable與Thread的區(qū)別詳解

    本篇文章是對在Android中Handler Runnable與Thread的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05

最新評論

黄山市| 五寨县| 木里| 普定县| 府谷县| 炉霍县| 潼南县| 仪陇县| 宁城县| 靖江市| 卓尼县| 台山市| 行唐县| 堆龙德庆县| 慈溪市| 南陵县| 临汾市| 涿鹿县| 徐水县| 津市市| 鹤壁市| 奇台县| 临西县| 彭州市| 沧源| 老河口市| 塔河县| 资兴市| 靖西县| 吴川市| 赣州市| 武鸣县| 陵水| 花莲市| 砀山县| 怀宁县| 吉林市| 海阳市| 剑河县| 杂多县| 岳池县|