/* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.example.android.apis.view;// Need the following import to get access to the app resources, since this// class is in a sub-package.import com.example.android.apis.R;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.animation.AnimationUtils;import android.view.animation.Animation;import android.view.animation.TranslateAnimation;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;public class Animation3 extends Activity implements AdapterView.OnItemSelectedListener {    private static final String[] INTERPOLATORS = {            "Accelerate", "Decelerate", "Accelerate/Decelerate",            "Anticipate", "Overshoot", "Anticipate/Overshoot",            "Bounce"    };    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.animation_3);        Spinner s = (Spinner) findViewById(R.id.spinner);        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,                android.R.layout.simple_spinner_item, INTERPOLATORS);        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);        s.setAdapter(adapter);        s.setOnItemSelectedListener(this);    }    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {        final View target = findViewById(R.id.target);        final View targetParent = (View) target.getParent();        Animation a = new TranslateAnimation(0.0f,                targetParent.getWidth() - target.getWidth() - targetParent.getPaddingLeft() -                targetParent.getPaddingRight(), 0.0f, 0.0f);        a.setDuration(1000);        a.setStartOffset(300);        a.setRepeatMode(Animation.RESTART);        a.setRepeatCount(Animation.INFINITE);        switch (position) {            case 0:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.accelerate_interpolator));                break;            case 1:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.decelerate_interpolator));                break;            case 2:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.accelerate_decelerate_interpolator));                break;            case 3:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.anticipate_interpolator));                break;            case 4:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.overshoot_interpolator));                break;            case 5:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.anticipate_overshoot_interpolator));                break;            case 6:                a.setInterpolator(AnimationUtils.loadInterpolator(this,                        android.R.anim.bounce_interpolator));                break;        }        target.startAnimation(a);    }    public void onNothingSelected(AdapterView<?> parent) {    }}


<?xml version="1.0" encoding="utf-8"?>

<accelerateDecelerateInterpolator />

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 总结Android中的Info系列类
  2. Android简单模糊背景和圆形ImageView
  3. android studio GC overhead limit excee
  4. Android自定义Toast样式和时间
  5. Android初学路上会遇到的瓶颈
  6. Android(安卓)viewpager里面嵌套使用list
  7. Android中的PCM设备
  8. android涓殑鏍峰紡涓婚鍜屽浗闄呭寲
  9. Android拍照识别身份证SDK
  10. android listview 数据加载错乱、错位、