編輯:關於Android編程
找到個不錯的開源項目:https://github.com/jfeinstein10/JazzyViewPager
Android ViewPager 動畫效果
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"/uploadfile/Collfiles/20141126/2014112608433590.png" alt="\">
適配器:(這個是viewpager的每一項都添加了onclick事件的)
package com.example.jaazy; import java.util.ArrayList; import android.support.v4.view.PagerAdapter; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; /** * Create by LanYan on 2014.04.24 * This is a adapter */ public class ViewPagerAdapterOnClick extends PagerAdapter { private ArrayListactivity:views; private ViewPageOnClick callback; private JazzyViewPager pager; public ViewPagerAdapterOnClick(JazzyViewPager pager,ArrayList views,ViewPageOnClick callback) { this.setViews(views); this.callback=callback; this.pager=pager; } public void setViews(ArrayList views) { if (views != null) this.views = views; else this.views = new ArrayList (); } public void changeItem(ArrayList views) { this.setViews(views); notifyDataSetChanged(); } @Override public int getItemPosition(Object object) { // TODO Auto-generated method stub return POSITION_NONE; } @Override public int getCount() { // TODO Auto-generated method stub return views.size(); } @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return arg0 == arg1; } @Override public void destroyItem(ViewGroup container, int position, Object object) { View v = views.get(position); container.removeView(v); } public void removeUpdate(ViewGroup container){ container.removeAllViews(); } @Override public Object instantiateItem(ViewGroup container, final int position) { View v = views.get(position); v.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub callback.callbackOnClickItem(position); } }); container.addView(v); pager.setObjectForPosition(v, position); return v; } public interface ViewPageOnClick{ void callbackOnClickItem(int position); } }
import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; import android.widget.Toast; import com.example.jaazy.JazzyViewPager.TransitionEffect; import com.example.jaazy.ViewPagerAdapterOnClick.ViewPageOnClick; public class MainActivity extends Activity implements ViewPageOnClick{ private JazzyViewPager pager; private ViewPagerAdapterOnClick adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupJazziness(TransitionEffect.Stack); } private void setupJazziness(TransitionEffect stack) { // TODO Auto-generated method stub pager=(JazzyViewPager)findViewById(R.id.jazzy_pager); adapter=new ViewPagerAdapterOnClick(pager, getViews(),this); pager.setAdapter(adapter); pager.setPageMargin(5); //壓棧方式 pager.setTransitionEffect(TransitionEffect.Stack); //立體內部進出 //pager.setTransitionEffect(TransitionEffect.CubeIn); //立體凸出 //pager.setTransitionEffect(TransitionEffect.CubeOut); //左右擠壓 //pager.setTransitionEffect(TransitionEffect.Accordion); //水平翻頁 //pager.setTransitionEffect(TransitionEffect.FlipHorizontal); //垂直翻頁 //pager.setTransitionEffect(TransitionEffect.FlipVertical); //上扇形擺入 //pager.setTransitionEffect(TransitionEffect.RotateDown); //下扇形擺入 //pager.setTransitionEffect(TransitionEffect.RotateUp); //標准 //pager.setTransitionEffect(TransitionEffect.Standard); //選項卡(卡片形式) ///pager.setTransitionEffect(TransitionEffect.Tablet); //zoom in //pager.setTransitionEffect(TransitionEffect.ZoomIn); //zoom out //pager.setTransitionEffect(TransitionEffect.ZoomOut); } private ArrayListJazzyViewPager自帶動畫枚舉11中,如需其他動畫,自己添加即可getViews() { // TODO Auto-generated method stub ArrayList list=new ArrayList (); ImageView i=new ImageView(this); LayoutParams params=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); i.setLayoutParams(params); i.setBackgroundResource(R.drawable.a); ImageView i2=new ImageView(this); i2.setLayoutParams(params); i2.setBackgroundResource(R.drawable.b); ImageView i3=new ImageView(this); i3.setLayoutParams(params); i3.setBackgroundResource(R.drawable.c); ImageView i4=new ImageView(this); i4.setLayoutParams(params); i4.setBackgroundResource(R.drawable.e); list.add(i); list.add(i2); list.add(i3); list.add(i4); return list; } @Override public void callbackOnClickItem(int position) { // TODO Auto-generated method stub Toast.makeText(this, "position:"+position, 1000).show(); } }
前言 成功的產品往往在細節之處也做到極致,產品和項目從使用的角度來看最大的區別我認為也就是細節的處理上。開播視頻的目標是產品,前面7篇文章高歌猛進,添加了很多的功能,也
起因: 最近在做一個新聞APP,看到現在的新聞客戶端頂端都有個熱點新聞輪播。思路:viewpager可以用來顯示圖片,並且可以提供滑動,15年(不知記錯沒)新出的TabL
(一)概述本節開始講解Android的四大組件之一的Activity(活動);官方文檔:Activity是一個應用程序的組件,他在屏幕上提供了一個區域,允許用戶在上面做一
據說小米手機已經成為全球第十一大手機商,第一個星期一百個用戶,第二個星期兩百個用戶,第三個星期四百個用戶,第五個星期八百個用戶,截至2013年上半年,小米手