最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android GridView實現(xiàn)動畫效果實現(xiàn)代碼

 更新時間:2017年03月16日 08:37:11   投稿:lqh  
這篇文章主要介紹了 Android GridView實現(xiàn)動畫效果實現(xiàn)代碼的相關資料,需要的朋友可以參考下

 Android GridView實現(xiàn)動畫效果

項目中用到的一些動畫,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 List<String> mList; 
  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); 
 
  } 
} 

GridAdapter.java

package com.mundane.gridanimationdemo; 
 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.animation.Animation; 
import android.view.animation.TranslateAnimation; 
import android.widget.BaseAdapter; 
import android.widget.TextView; 
 
import java.util.List; 
 
/** 
 * Created by Jackie on 2017/3/7 16:29 
 */ 
 
public class GridAdapter extends BaseAdapter{ 
  private List<String> mList; 
 
  public GridAdapter(List<String> list) { 
    mList = list; 
  } 
 
  @Override 
  public int getCount() { 
    return mList.size(); 
  } 
 
  @Override 
  public Object getItem(int position) { 
    return mList.get(position); 
  } 
 
  @Override 
  public long getItemId(int position) { 
    return position; 
  } 
 
  @Override 
  public View getView(final int position, View convertView, ViewGroup parent) { 
    String text = mList.get(position); 
    ViewHolder holder; 
    if (convertView == null) { 
      convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_desk_grid_item, parent, false); 
      holder = new ViewHolder(convertView); 
      convertView.setTag(holder); 
    } else { 
      holder = (ViewHolder) convertView.getTag(); 
    } 
    convertView.setVisibility(View.INVISIBLE); 
    holder.textView.setText(text); 
    int count = 3 - position % 3; 
    final TranslateAnimation translateAnimation = new TranslateAnimation( 
        Animation.RELATIVE_TO_SELF, 
        count, 
        Animation.RELATIVE_TO_SELF, 
        0, 
        Animation.RELATIVE_TO_SELF, 
        0, 
        Animation.RELATIVE_TO_SELF, 
        0); 
    translateAnimation.setDuration(count* 100); 
//   final Animation animation = AnimationUtils.loadAnimation(parent.getContext(), R.anim.slide_in_right); 
    final View finalConvertView = convertView; 
    convertView.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
        finalConvertView.startAnimation(translateAnimation); 
      } 
    }, position * 200); 
    translateAnimation.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 
        finalConvertView.setVisibility(View.VISIBLE); 
      } 
 
      @Override 
      public void onAnimationEnd(Animation animation) { 
        if (position == mList.size() - 1) { 
          if (mListener != null) { 
            mListener.onAnimationEnd(); 
          } 
        } 
      } 
 
      @Override 
      public void onAnimationRepeat(Animation animation) { 
 
      } 
    }); 
 
    return convertView; 
  } 
 
  static class ViewHolder { 
    TextView textView; 
     
    public ViewHolder(View view) { 
      textView = (TextView) view.findViewById(R.id.tv); 
    } 
  } 
 
  public interface OnLastItemAnimationEndListener { 
    void onAnimationEnd(); 
  } 
 
  private OnLastItemAnimationEndListener mListener; 
 
  public void setOnLastItemAnimationEndListener(OnLastItemAnimationEndListener listener) { 
    mListener = listener; 
  } 
} 

參上上面的代碼,還可以實現(xiàn)GridView Item的其他動畫效果,注意//注釋的部分,這個就是另外的動畫效果,這里就不作過多的描述。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:app="http://schemas.android.com/apk/res-auto" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  tools:context="com.mundane.gridanimationdemo.MainActivity"> 
 
  <Button 
    android:visibility="invisible" 
    android:id="@+id/btn_refresh" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="刷新"/> 
 
  <GridView 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="10dp" 
    android:stretchMode="columnWidth" 
    android:id="@+id/grid_view" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#f6f6f6" 
    android:horizontalSpacing="10dp" 
    android:numColumns="3" 
    android:scrollbars="none" 
    android:verticalSpacing="10dp"> 
 
  </GridView> 
 
 
</LinearLayout> 

card_desk_grid_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:background="#33000000" 
  android:layout_width="match_parent" 
  android:layout_height="156dp"> 
  <TextView 
    android:id="@+id/tv" 
    android:gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 
</LinearLayout> 

效果如下:

模擬器上運行很卡,真機上是很流暢的。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • Android自定義View實現(xiàn)氣泡動畫

    Android自定義View實現(xiàn)氣泡動畫

    這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)氣泡動畫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android使用ViewDragHelper實現(xiàn)QQ6.X最新版本側滑界面效果實例代碼

    Android使用ViewDragHelper實現(xiàn)QQ6.X最新版本側滑界面效果實例代碼

    這篇文章主要介紹了Android程序開發(fā)實現(xiàn)QQ6.X最新版本側滑界面效果實例代碼的相關資料,需要的朋友可以參考下
    2016-02-02
  • Android View進行手勢識別詳解

    Android View進行手勢識別詳解

    本文主要介紹 Android View進行手勢識別,這里整理了相關資料和簡單示例,有興趣的小伙伴可以參考下
    2016-08-08
  • Android的WebView與H5前端JS代碼交互的實例代碼

    Android的WebView與H5前端JS代碼交互的實例代碼

    本篇文章主要介紹了Android的WebView與H5前端JS代碼交互的實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-07-07
  • 基于Android本地代碼生成器詳解

    基于Android本地代碼生成器詳解

    本篇文章是對Android本地代碼生成器的使用進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • Android網絡編程之簡易新聞客戶端

    Android網絡編程之簡易新聞客戶端

    這篇文章主要為大家詳細介紹了Android網絡編程之簡易新聞客戶端的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • android頂部(toolbar)搜索框實現(xiàn)代碼

    android頂部(toolbar)搜索框實現(xiàn)代碼

    這篇文章主要介紹了android頂部(toolbar)搜索框實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android自定義圖片集合

    Android自定義圖片集合

    這篇文章主要為大家分享了內容相當豐富的Android自定義圖片集合,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • 淺析Android.mk

    淺析Android.mk

    Android.mk是Android提供的一種makefile文件,用來指定諸如編譯生成so庫名、引用的頭文件目錄、需要編譯的.c/.cpp文件和.a靜態(tài)庫文件等。要掌握jni,就必須熟練掌握Android.mk的語法規(guī)范
    2016-01-01
  • 淺談Android PathMeasure詳解和應用

    淺談Android PathMeasure詳解和應用

    本篇文章主要介紹了淺談Android PathMeasure詳解和應用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01

最新評論

荆门市| 双城市| 渝北区| 连云港市| 甘孜| 涞水县| 杭锦旗| 和林格尔县| 交城县| 阳高县| 永年县| 久治县| 中西区| 师宗县| 桃园市| 永登县| 千阳县| 三台县| 青神县| 闽侯县| 星子县| 新建县| 连城县| 利辛县| 通渭县| 宣恩县| 兴安盟| 永昌县| 诏安县| 乌兰察布市| 都昌县| 临江市| 蒙自县| 罗山县| 宽甸| 扶沟县| 舟曲县| 娄底市| 和静县| 文成县| 尼木县|