├── .idea └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── bluemobi │ │ └── dylan │ │ └── animationdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── bluemobi │ │ │ └── dylan │ │ │ └── animationdemo │ │ │ ├── MainActivity.java │ │ │ ├── SecondActivity.java │ │ │ └── adapter │ │ │ ├── CommonAdapter.java │ │ │ └── CommonViewHolder.java │ └── res │ │ ├── anim │ │ ├── alpha.xml │ │ ├── group2.xml │ │ ├── push_left_in.xml │ │ ├── push_left_out.xml │ │ ├── push_right_in.xml │ │ ├── push_right_out.xml │ │ ├── rotate.xml │ │ ├── scale.xml │ │ ├── translate.xml │ │ ├── zoom_in.xml │ │ └── zoom_out.xml │ │ ├── drawable │ │ └── ring_animation.xml │ │ ├── layout │ │ ├── ac_second.xml │ │ ├── activity_main.xml │ │ └── item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── promb_voice.png │ │ ├── promb_voice2.png │ │ ├── promb_voice3.png │ │ ├── windmill_1.JPG │ │ ├── windmill_2.JPG │ │ ├── windmill_3.JPG │ │ ├── windmill_4.JPG │ │ ├── windmill_5.JPG │ │ ├── windmill_6.JPG │ │ └── windmill_7.JPG │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── bluemobi │ └── dylan │ └── animationdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshorts ├── effect.gif └── 示例图.jpg ├── screenshots └── effect.gif └── settings.gradle /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | >Android中常用的动画都在这里了,包含了基本的动画【透明度动画,缩放动画,旋转动画,位移动画】;还有就是这四种动画的组合实现; 2 | 还有布局动画,就是在加载布局时的动画;还有Activity跳转的动画。 3 | 效果图如下: 4 | 5 | ![效果图](https://github.com/linglongxin24/AnimationDemo/blob/master/screenshorts/effect.gif?raw=true) 6 | 7 | #1. Android基础动画 8 | 9 | * 透明度动画 10 | 11 | ```xml 12 | 13 | 14 | 19 | 20 | ``` 21 | 22 | ```java 23 | /** 24 | * 第一个参数fromAlpha为 动画开始时候透明度 25 | *第二个参数toAlpha为 动画结束时候透明度 26 | */ 27 | Animation animation = new AlphaAnimation(0, 1); 28 | animation.setDuration(1000); 29 | v.startAnimation(animation); 30 | ``` 31 | 32 | * 缩放动画 33 | 34 | ```xml 35 | 36 | 37 | 45 | 46 | ``` 47 | 48 | ```java 49 | /** 50 | * 第一个参数fromX为动画起始时 X坐标上的伸缩尺寸 51 | * 第二个参数toX为动画结束时 X坐标上的伸缩尺寸 52 | * 第三个参数fromY为动画起始时Y坐标上的伸缩尺寸 53 | * 第四个参数toY为动画结束时Y坐标上的伸缩尺寸 54 | * 说明: 0.0表示收缩到没有;1.0表示正常无伸缩;值小于1.0表示收缩;值大于1. 55 | * 第五个参数pivotXType为动画在X轴相对于物件位置类型 56 | * 第六个参数pivotXValue为动画相对于物件的X坐标的开始位置 57 | * 第七个参数pivotXType为动画在Y轴相对于物件位置类型 58 | * 第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置 59 | */ 60 | Animation animation = new ScaleAnimation(0, 1 61 | animation.setDuration(1000); 62 | iv.startAnimation(animation); 63 | ``` 64 | 65 | * 旋转动画 66 | 67 | ```xml 68 | 69 | 70 | 76 | 77 | ``` 78 | 79 | ```java 80 | /** 81 | * 第一个参数fromDegrees为动画起始时角度 82 | * 第二个参数toDegrees为动画结束角度 83 | * 第三个参数pivotXType为动画在X轴相对于物件位置类型 84 | * 第四个参数pivotXValue为动画相对于物件的X坐标的开始位置 85 | * 第五个参数pivotXType为动画在Y轴相对于物件位置类型 86 | * 第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置 87 | */ 88 | Animation animation = new RotateAnima 89 | animation.setDuration(1000); 90 | iv.startAnimation(animation); 91 | ``` 92 | 93 | 94 | * 位移动画 95 | 96 | ```xml 97 | 98 | 99 | 106 | 107 | ``` 108 | 109 | ```java 110 | /** 111 | * 第一个参数fromDegrees为动画起始时角度 112 | * 第二个参数toDegrees为动画结束角度 113 | * 第三个参数pivotXType为动画在X轴相对于物件位置类型 114 | * 第四个参数pivotXValue为动画相对于物件的X坐标的开始位置 115 | * 第五个参数pivotXType为动画在Y轴相对于物件位置类型 116 | * 第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置 117 | */ 118 | Animation animation = new RotateAnima 119 | animation.setDuration(1000); 120 | iv.startAnimation(animation); 121 | /** 122 | * 第一个参数fromXDelta为动画起始时的x坐标 123 | * 第二个参数toXDelta为动画结束时的x坐标 124 | * 第三个参数fromYDelta为动画起始时的y坐标 125 | * 第四个参数toYDelta为动画结束时的y坐标 126 | */ 127 | Animation animation = new Translat 128 | animation.setDuration(2000); 129 | /**设置插值器:先加速,后减速**/ 130 | animation.setInterpolator(new Acce 131 | iv.startAnimation(animation); 132 | ``` 133 | #2.组合动画 134 | 135 | * 先播放缩放动画,完成后播放旋转动画 136 | 137 | ```java 138 | Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale); 139 | iv.startAnimation(animation); 140 | final Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.rotate); 141 | animation.setAnimationListener(new Animation.AnimationListener() { 142 | @Override 143 | public void onAnimationStart(Animation animation) { 144 | 145 | } 146 | 147 | @Override 148 | public void onAnimationEnd(Animation animation) { 149 | 150 | iv.startAnimation(animation2); 151 | } 152 | 153 | @Override 154 | public void onAnimationRepeat(Animation animation) { 155 | 156 | } 157 | }); 158 | ``` 159 | 160 | * 先播放旋转动画,完成后播放位移动画,在xml中设置第二个动画执行的等待时间 161 | 162 | ```xml 163 | 164 | 165 | 166 | 172 | 180 | 181 | ``` 182 | 183 | * 重复的透明度动画-闪烁 184 | 185 | ```java 186 | AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); 187 | alphaAnimation.setDuration(1000); 188 | alphaAnimation.setRepeatCount(10); 189 | /**倒序重复REVERSE 正序重复RESTART**/ 190 | alphaAnimation.setRepeatMode(Animation.REVERSE); 191 | iv.startAnimation(alphaAnimation); 192 | ``` 193 | 194 | * 重复的位移动画-抖动 195 | 196 | ```java 197 | Animation translateAnimation = new TranslateAnimation(-10, 10, 0, 0); 198 | translateAnimation.setDuration(100); 199 | translateAnimation.setRepeatCount(10); 200 | /**倒序重复REVERSE 正序重复RESTART**/ 201 | translateAnimation.setRepeatMode(Animation.REVERSE); 202 | iv.startAnimation(translateAnimation); 203 | ``` 204 | 205 | #3.帧动画 206 | 207 | * 在drawable文件夹下建立文件 208 | 209 | ```xml 210 | 211 | 213 | 215 | 216 | 218 | 219 | 221 | 222 | 224 | 225 | 227 | 228 | 230 | 231 | 233 | 234 | 235 | 236 | 237 | ``` 238 | * 在activity中调用 239 | 240 | ```java 241 | iv.setImageResource(R.drawable.ring_animation); 242 | AnimationDrawable animationDrawable = (AnimationDrawable) iv.getDrawable(); 243 | animationDrawable.start(); 244 | ``` 245 | #4.布局动画 246 | 这是一个ListView的加载布局动画 247 | 248 | * 先建立动画文件,从透明到不透明并且大小从0到原大小 249 | 250 | ```xml 251 | 252 | 254 | 255 | 263 | 267 | 268 | ``` 269 | 270 | * 在activity中的用法 271 | 272 | ```java 273 | ListView listView = (ListView) findViewById(R.id.listview); 274 | List datas = new ArrayList<>(); 275 | for (int i = 0; i < 18; i++) { 276 | datas.add("万能适配器测试" + i); 277 | } 278 | LayoutAnimationController layoutAnimationController= new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.zoom_in)); 279 | layoutAnimationController.setOrder(LayoutAnimationController.ORDER_NORMAL); 280 | listView.setLayoutAnimation(layoutAnimationController); 281 | listView.setAdapter(new CommonAdapter(this, datas, R.layout.item) { 282 | 283 | @Override 284 | protected void convertView(View item, String s) { 285 | TextView textView = CommonViewHolder.get(item, R.id.textView); 286 | textView.setText(s); 287 | } 288 | }); 289 | ``` 290 | #5.Activity跳转动画 291 | 292 | * 退出动画:从不透明到透明并且大小从原大小到0 293 | 294 | ```xml 295 | 296 | 299 | 300 | 308 | 309 | 313 | 314 | 315 | ``` 316 | 317 | * 进入动画:从透明到不透明并且大小从0到原大小 318 | 319 | ```xml 320 | 321 | 323 | 324 | 332 | 336 | 337 | ``` 338 | 339 | * 在Activity中的用法 340 | 341 | ```java 342 | startActivity(new Intent(this,SecondActivity.class)); 343 | overridePendingTransition(R.anim.zoom_in,R.anim.zoom_out); 344 | ``` 345 | #6.[GitHub](https://github.com/linglongxin24/AnimationDemo) 346 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "cn.bluemobi.dylan.animationdemo" 8 | minSdkVersion 9 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.0.0' 28 | testCompile 'junit:junit:4.12' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\kejiang\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/cn/bluemobi/dylan/animationdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.bluemobi.dylan.animationdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("cn.bluemobi.dylan.animatordemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/cn/bluemobi/dylan/animationdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.bluemobi.dylan.animationdemo; 2 | 3 | import android.content.Intent; 4 | import android.graphics.drawable.AnimationDrawable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.animation.AccelerateDecelerateInterpolator; 9 | import android.view.animation.AlphaAnimation; 10 | import android.view.animation.Animation; 11 | import android.view.animation.AnimationUtils; 12 | import android.view.animation.Interpolator; 13 | import android.view.animation.LayoutAnimationController; 14 | import android.view.animation.RotateAnimation; 15 | import android.view.animation.ScaleAnimation; 16 | import android.view.animation.TranslateAnimation; 17 | import android.widget.ImageView; 18 | import android.widget.ListView; 19 | import android.widget.TextView; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import cn.bluemobi.dylan.animationdemo.adapter.CommonAdapter; 25 | import cn.bluemobi.dylan.animationdemo.adapter.CommonViewHolder; 26 | 27 | public class MainActivity extends AppCompatActivity { 28 | private boolean fromXml = true; 29 | private ImageView iv; 30 | 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | iv = (ImageView) findViewById(R.id.iv); 37 | } 38 | 39 | public void onClick(View v) { 40 | iv.setImageResource(R.mipmap.ic_launcher); 41 | switch (v.getId()) { 42 | case R.id.animation_alpha://透明度渐变动画 43 | if (fromXml) { 44 | Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha); 45 | iv.startAnimation(animation); 46 | } else { 47 | /** 48 | * 第一个参数fromAlpha为 动画开始时候透明度 49 | *第二个参数toAlpha为 动画结束时候透明度 50 | */ 51 | Animation animation = new AlphaAnimation(0, 1); 52 | animation.setDuration(1000); 53 | iv.startAnimation(animation); 54 | } 55 | break; 56 | case R.id.animation_scale://缩放动画 57 | if (fromXml) { 58 | Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale); 59 | iv.startAnimation(animation); 60 | } else { 61 | /** 62 | * 第一个参数fromX为动画起始时 X坐标上的伸缩尺寸 63 | * 第二个参数toX为动画结束时 X坐标上的伸缩尺寸 64 | * 第三个参数fromY为动画起始时Y坐标上的伸缩尺寸 65 | * 第四个参数toY为动画结束时Y坐标上的伸缩尺寸 66 | * 说明: 0.0表示收缩到没有;1.0表示正常无伸缩;值小于1.0表示收缩;值大于1.0表示放大 67 | 68 | * 第五个参数pivotXType为动画在X轴相对于物件位置类型 69 | * 第六个参数pivotXValue为动画相对于物件的X坐标的开始位置 70 | * 第七个参数pivotXType为动画在Y轴相对于物件位置类型 71 | * 第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置 72 | */ 73 | Animation animation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 74 | animation.setDuration(1000); 75 | iv.startAnimation(animation); 76 | } 77 | break; 78 | case R.id.animation_rotate://旋转动画 79 | if (fromXml) { 80 | Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate); 81 | iv.startAnimation(animation); 82 | } else { 83 | /** 84 | * 第一个参数fromDegrees为动画起始时角度 85 | * 第二个参数toDegrees为动画结束角度 86 | * 第三个参数pivotXType为动画在X轴相对于物件位置类型 87 | * 第四个参数pivotXValue为动画相对于物件的X坐标的开始位置 88 | * 第五个参数pivotXType为动画在Y轴相对于物件位置类型 89 | * 第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置 90 | */ 91 | Animation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 92 | animation.setDuration(1000); 93 | iv.startAnimation(animation); 94 | } 95 | break; 96 | case R.id.animation_translate://位移动画 97 | if (fromXml) { 98 | Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate); 99 | iv.startAnimation(animation); 100 | } else { 101 | /** 102 | * 第一个参数fromXDelta为动画起始时的x坐标 103 | * 第二个参数toXDelta为动画结束时的x坐标 104 | * 第三个参数fromYDelta为动画起始时的y坐标 105 | * 第四个参数toYDelta为动画结束时的y坐标 106 | */ 107 | Animation animation = new TranslateAnimation(0, 500, 0, 0); 108 | animation.setDuration(2000); 109 | /**设置插值器:先加速,后减速**/ 110 | animation.setInterpolator(new AccelerateDecelerateInterpolator()); 111 | iv.startAnimation(animation); 112 | } 113 | break; 114 | case R.id.animation_group1://先播放缩放动画,完成后播放旋转动画 115 | Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale); 116 | iv.startAnimation(animation); 117 | final Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.rotate); 118 | animation.setAnimationListener(new Animation.AnimationListener() { 119 | @Override 120 | public void onAnimationStart(Animation animation) { 121 | 122 | } 123 | 124 | @Override 125 | public void onAnimationEnd(Animation animation) { 126 | 127 | iv.startAnimation(animation2); 128 | } 129 | 130 | @Override 131 | public void onAnimationRepeat(Animation animation) { 132 | 133 | } 134 | }); 135 | break; 136 | case R.id.animation_group2://先播放旋转动画,完成后播放位移动画,在xml中设置第二个动画执行的等待时间 137 | Animation animationGroup = AnimationUtils.loadAnimation(this, R.anim.group2); 138 | iv.startAnimation(animationGroup); 139 | break; 140 | case R.id.animation_group3://重复的透明度动画 141 | AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); 142 | alphaAnimation.setDuration(1000); 143 | alphaAnimation.setRepeatCount(10); 144 | /**倒序重复REVERSE 正序重复RESTART**/ 145 | alphaAnimation.setRepeatMode(Animation.REVERSE); 146 | iv.startAnimation(alphaAnimation); 147 | break; 148 | case R.id.animation_group4://重复的位移动画 149 | Animation translateAnimation = new TranslateAnimation(-10, 10, 0, 0); 150 | translateAnimation.setDuration(100); 151 | translateAnimation.setRepeatCount(10); 152 | /**倒序重复REVERSE 正序重复RESTART**/ 153 | translateAnimation.setRepeatMode(Animation.REVERSE); 154 | iv.startAnimation(translateAnimation); 155 | break; 156 | case R.id.animation_frame://帧动画 157 | iv.setImageResource(R.drawable.ring_animation); 158 | AnimationDrawable animationDrawable = (AnimationDrawable) iv.getDrawable(); 159 | animationDrawable.start(); 160 | break; 161 | case R.id.animation_layout://布局动画 162 | commonAdapterTest(); 163 | break; 164 | case R.id.animation_activity://activity跳转动画 165 | startActivity(new Intent(this,SecondActivity.class)); 166 | overridePendingTransition(R.anim.zoom_out,R.anim.zoom_in); 167 | break; 168 | } 169 | 170 | } 171 | 172 | /** 173 | * 布局动画 174 | */ 175 | private void commonAdapterTest() { 176 | ListView listView = (ListView) findViewById(R.id.listview); 177 | List datas = new ArrayList<>(); 178 | for (int i = 0; i < 18; i++) { 179 | datas.add("万能适配器测试" + i); 180 | } 181 | LayoutAnimationController layoutAnimationController= new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.zoom_in)); 182 | layoutAnimationController.setOrder(LayoutAnimationController.ORDER_NORMAL); 183 | listView.setLayoutAnimation(layoutAnimationController); 184 | listView.setAdapter(new CommonAdapter(this, datas, R.layout.item) { 185 | 186 | @Override 187 | protected void convertView(View item, String s) { 188 | TextView textView = CommonViewHolder.get(item, R.id.textView); 189 | textView.setText(s); 190 | } 191 | }); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /app/src/main/java/cn/bluemobi/dylan/animationdemo/SecondActivity.java: -------------------------------------------------------------------------------- 1 | package cn.bluemobi.dylan.animationdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | /** 9 | * Created by yuandl on 2016-11-08. 10 | */ 11 | 12 | public class SecondActivity extends AppCompatActivity { 13 | @Override 14 | protected void onCreate(@Nullable Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.ac_second); 17 | } 18 | public void onClick(View v){ 19 | finish(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/cn/bluemobi/dylan/animationdemo/adapter/CommonAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.bluemobi.dylan.animationdemo.adapter; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ListView; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by yuandl on 2016-10-13. 15 | * 万能适配器 16 | */ 17 | 18 | public abstract class CommonAdapter extends BaseAdapter { 19 | private Context context; 20 | private List datas; 21 | private int layoutId; 22 | 23 | public CommonAdapter(Context context, List datas, int layoutId) { 24 | this.context = context; 25 | this.datas = datas; 26 | this.layoutId = layoutId; 27 | } 28 | 29 | @Override 30 | public int getCount() { 31 | return datas == null ? 0 : datas.size(); 32 | } 33 | 34 | @Override 35 | public T getItem(int position) { 36 | return datas.get(position); 37 | } 38 | 39 | @Override 40 | public long getItemId(int position) { 41 | return position; 42 | } 43 | 44 | @Override 45 | public View getView(int position, View convertView, ViewGroup parent) { 46 | if (convertView == null) { 47 | Log.d("listview", "---------LayoutInflater()-----------" + position); 48 | convertView = LayoutInflater.from(context).inflate(layoutId, null); 49 | }else{ 50 | } 51 | // Log.d("listview", "---------getView()-----------" + position); 52 | T t = getItem(position); 53 | convertView(convertView, t); 54 | return convertView; 55 | } 56 | 57 | /** 58 | * 局部更新数据,调用一次getView()方法;Google推荐的做法 59 | * 60 | * @param listView 要更新的listview 61 | * @param position 要更新的位置 62 | */ 63 | public void notifyDataSetChanged(ListView listView, int position) { 64 | /**第一个可见的位置**/ 65 | int firstVisiblePosition = listView.getFirstVisiblePosition(); 66 | /**最后一个可见的位置**/ 67 | int lastVisiblePosition = listView.getLastVisiblePosition(); 68 | 69 | /**在看见范围内才更新,不可见的滑动后自动会调用getView方法更新**/ 70 | if (position >= firstVisiblePosition && position <= lastVisiblePosition) { 71 | /**获取指定位置view对象**/ 72 | View view = listView.getChildAt(position - firstVisiblePosition); 73 | getView(position, view, listView); 74 | } 75 | 76 | } 77 | 78 | /** 79 | * 需要去实现的对item中的view的设置操作 80 | * 81 | * @param item 82 | * @param t 83 | */ 84 | protected abstract void convertView(View item, T t); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/cn/bluemobi/dylan/animationdemo/adapter/CommonViewHolder.java: -------------------------------------------------------------------------------- 1 | package cn.bluemobi.dylan.animationdemo.adapter; 2 | 3 | 4 | import android.util.SparseArray; 5 | import android.view.View; 6 | 7 | /** 8 | * Created by yuandl on 2016-10-13. 9 | * 万能的ViewHolder 10 | * 11 | * @author 12 | */ 13 | public class CommonViewHolder { 14 | /** 15 | * @param view 所有缓存View的根View 16 | * @param id 缓存View的唯一标识 17 | * @return 18 | */ 19 | public static T get(View view, int id) { 20 | 21 | SparseArray viewHolder = (SparseArray) view.getTag(); 22 | //如果根view没有用来缓存View的集合 23 | if (viewHolder == null) { 24 | viewHolder = new SparseArray(); 25 | view.setTag(viewHolder);//创建集合和根View关联 26 | } 27 | View chidlView = viewHolder.get(id);//获取根View储存在集合中的孩纸 28 | if (chidlView == null) {//如果没有改孩纸 29 | //找到该孩纸 30 | chidlView = view.findViewById(id); 31 | viewHolder.put(id, chidlView);//保存到集合 32 | } 33 | return (T) chidlView; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/res/anim/alpha.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/group2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/anim/push_left_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/push_left_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/push_right_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/push_right_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/rotate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/scale.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/anim/translate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/anim/zoom_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/anim/zoom_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ring_animation.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/ac_second.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |