1. 很简单的属性动画使用
package com.yufeiyang.android_button; import java.util.ArrayList; import java.util.List; import android.animation.ObjectAnimator; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.OvershootInterpolator; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { private int[] res = { R.id.imageView1, R.id.imageView2, R.id.imageView3, R.id.imageView4, R.id.imageView5, R.id.imageView6, R.id.imageView7 }; private int[] res_layout = { R.id.layout1, R.id.layout2, R.id.layout3, R.id.layout4, R.id.layout5, R.id.layout6, R.id.layout7 }; private int[] text_tv = { R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6, R.id.textView7 }; private List<ImageView> imageList = new ArrayList<ImageView>(); private List<LinearLayout> layoutList = new ArrayList<LinearLayout>(); private List<TextView> textlist = new ArrayList<TextView>(); boolean isOpen = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } public void init() { for (int i = 0; i < res.length; i++) { ImageView imageView = (ImageView) this.findViewById(res[i]); imageView.setOnClickListener(this); imageList.add(imageView); } for (int i = 0; i < res_layout.length; i++) { LinearLayout layout = (LinearLayout) this .findViewById(res_layout[i]); layout.setOnClickListener(this); layoutList.add(layout); } for (int i = 0; i < text_tv.length; i++) { TextView textView = (TextView) this.findViewById(text_tv[i]); textView.setVisibility(View.INVISIBLE); textlist.add(textView); } } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.imageView1: if (!isOpen) { startAnim(); isOpen = true; } else { endAnim(); isOpen = false; } break; case R.id.imageView2: Toast.makeText(MainActivity.this, "ererer", Toast.LENGTH_LONG) .show(); break; case R.id.imageView3: Toast.makeText(MainActivity.this, "333", Toast.LENGTH_LONG).show(); break; case R.id.imageView4: Toast.makeText(MainActivity.this, "four", Toast.LENGTH_LONG).show(); break; case R.id.imageView5: Toast.makeText(MainActivity.this, "five", Toast.LENGTH_LONG).show(); break; case R.id.imageView6: Toast.makeText(MainActivity.this, "six", Toast.LENGTH_LONG).show(); break; case R.id.imageView7: Toast.makeText(MainActivity.this, "seven", Toast.LENGTH_LONG) .show(); break; default: break; } } public void startAnim() { for (int i = 0; i < res_layout.length; i++) { ObjectAnimator animator = ObjectAnimator.ofFloat(layoutList.get(i), "translationY", 0F, -200 * i); animator.setDuration(500); animator.setStartDelay(200 * i); animator.start(); } for (int i = 0; i < text_tv.length; i++) { ObjectAnimator animator = ObjectAnimator.ofFloat(textlist.get(i), "translationX", 0F); animator.setDuration(500); animator.setInterpolator(new OvershootInterpolator()); animator.setStartDelay(200 * i); animator.start(); textlist.get(i).setVisibility(View.VISIBLE); } } public void endAnim() { for (int i = 0; i < res_layout.length; i++) { ObjectAnimator animator = ObjectAnimator.ofFloat(layoutList.get(i), "translationY", -160 * i, 0F); animator.setDuration(500); animator.setInterpolator(new OvershootInterpolator()); animator.setStartDelay(200 * i); animator.start(); } for (int i = 0; i < text_tv.length; i++) { ObjectAnimator animator = ObjectAnimator.ofFloat(textlist.get(i), "translationX", 0F, 160 * i); animator.setDuration(500); animator.setInterpolator(new OvershootInterpolator()); animator.setStartDelay(200 * i); animator.start(); textlist.get(i).setVisibility(View.INVISIBLE); // textlist.get(i).setf } } }
2. 布局文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/FrameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <LinearLayout android:id="@+id/layout2" android:layout_width="match_parent" android:layout_height="50dp" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center_vertical" android:text="TextView111" /> <ImageView android:id="@+id/imageView2" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/one" /> </LinearLayout> <LinearLayout android:id="@+id/layout3" android:layout_width="match_parent" android:layout_height="50dp" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center_vertical" android:text="TextView222" /> <ImageView android:id="@+id/imageView3" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/two" /> </LinearLayout> <LinearLayout android:id="@+id/layout4" android:layout_width="match_parent" android:layout_height="50dp" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center_vertical" android:text="TextView333" /> <ImageView android:id="@+id/imageView4" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/three" /> </LinearLayout> <LinearLayout android:id="@+id/layout5" android:layout_width="match_parent" android:layout_height="50dp" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center_vertical" android:text="TextView444" /> <ImageView android:id="@+id/imageView5" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/four" /> </LinearLayout> <LinearLayout android:id="@+id/layout6" android:layout_width="match_parent" android:layout_height="50dp" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center_vertical" android:text="TextView555" /> <ImageView android:id="@+id/imageView6" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/five" /> </LinearLayout> <LinearLayout android:id="@+id/layout7" android:layout_width="match_parent" android:layout_height="50dp" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center_vertical" android:text="TextView666" /> <ImageView android:id="@+id/imageView7" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/six" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:id="@+id/layout1" android:layout_gravity="right|bottom" android:gravity="right|bottom" > <ImageView android:id="@+id/imageView1" android:layout_width="50dp" android:layout_height="50dp" android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/zero" /> </LinearLayout> </FrameLayout>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦