国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現循環平移動畫示例

2020-04-11 11:30:04
字體:
來源:轉載
供稿:網友

實現用一張背景圖做循環從左往右平移動畫。

1、實現兩個animation xml文件,一個起始位置在-100%p ,一個在0%p。設置repeat屬性為循環,重復。

復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="0%p" android:toXDelta="100%p"
        android:repeatMode="restart"
        android:interpolator="@android:anim/linear_interpolator"
        android:repeatCount="infinite"
        android:duration="30000" />
</set>

復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="-100%p" android:toXDelta="0%p"
        android:repeatMode="restart"
        android:interpolator="@android:anim/linear_interpolator"
        android:repeatCount="infinite"
        android:duration="30000" />
</set>

2、在view的layout里面放兩個一樣的view做背景,view的動畫分別對應上面那兩個animation。
復制代碼 代碼如下:

        <ImageView
             android:id="@+id/animation_top_left"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:contentDescription="@string/logo"
             android:src="@drawable/home_animation_bg" />
         <ImageView
             android:id="@+id/animation_top_right"  android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:contentDescription="@string/logo"
             android:src="@drawable/home_animation_bg" />

復制代碼 代碼如下:

Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.home_animation);
ImageView animationTopRightView = (ImageView)this.findViewById(R.id.animation_top_right);
animationTopRightView.startAnimation(anim);

復制代碼 代碼如下:

Animation anim2 = AnimationUtils.loadAnimation(mContext, R.anim.home_animation2);
ImageView animationTopLeftView = (ImageView)this.findViewById(R.id.animation_top_left);
animationTopLeftView.startAnimation(anim2);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都匀市| 清徐县| 南木林县| 无为县| 大悟县| 开鲁县| 民县| 区。| 中卫市| 江源县| 扬州市| 峨眉山市| 梅河口市| 章丘市| 四子王旗| 米泉市| 甘肃省| 贺州市| 观塘区| 汝南县| 大连市| 马鞍山市| 荔波县| 保山市| 当涂县| 明溪县| 鸡西市| 石河子市| 双江| 高陵县| 安福县| 龙井市| 同江市| 普安县| 故城县| 全州县| 海口市| 海口市| 北碚区| 醴陵市| 武城县|