Android GridView实现动画效果
创新互联建站成都企业网站建设服务,提供网站设计制作、成都网站设计网站开发,网站定制,建网站,网站搭建,网站设计,响应式网站开发,网页设计师打造企业风格网站,提供周到的售前咨询和贴心的售后服务。欢迎咨询做网站需要多少钱:18980820575项目中用到的一些动画,GridView的Item依次从屏幕外飞入到相应位置,附上相关代码:
MainActivity.Java
package com.mundane.gridanimationdemo; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.GridView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private GridView mGridView; private ListmList; private GridAdapter mGridAdapter; private Button mBtnRefresh; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGridView = (GridView) findViewById(R.id.grid_view); mBtnRefresh = (Button) findViewById(R.id.btn_refresh); mBtnRefresh.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mBtnRefresh.setVisibility(View.INVISIBLE); mGridAdapter.notifyDataSetChanged(); } }); mList = new ArrayList<>(); for (int i = 0; i < 9; i++) { mList.add(i + ""); } mGridAdapter = new GridAdapter(mList); final TranslateAnimation animation = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); animation.setDuration(200); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { mBtnRefresh.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mGridAdapter.setOnLastItemAnimationEndListener(new GridAdapter.OnLastItemAnimationEndListener() { @Override public void onAnimationEnd() { mBtnRefresh.startAnimation(animation); } }); mGridView.setAdapter(mGridAdapter); } }