2014-11-05 210 views
0

我用下面的代碼創建了10個片段,使您的手指從右到左和從左到右滾動。Android - 幻燈片動畫滾動片段

如何添加「動畫」片段的滾動不成爲默認動畫適應我的代碼?謝謝

JAVA

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.detalle_monumento_view); 

    List<Fragment> fragments = getFragments(); 

    pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments); 

    pager = (ViewPager)findViewById(R.id.viewpager); 
    pager.setAdapter(pageAdapter);  
    pager.setOnPageChangeListener(this); 
} 

private List<Fragment> getFragments(){ 

    List<Fragment> fList = new ArrayList<Fragment>(); 

    for(int i = 0; i < 10; i++) { 

     fList.add(DetalleMonumentoFragment.newInstance()); 
    } 

    return fList; 
} 

private class MyPageAdapter extends FragmentPagerAdapter { 

    private List<Fragment> fragments; 

    public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) { 
     super(fm); 
     this.fragments = fragments; 
    } 
    @Override 
    public Fragment getItem(int position) { 

     return this.fragments.get(position); 
    } 

    @Override 
    public int getCount() { 
     return this.fragments.size(); 
    } 
} 

回答

0

實施重點監聽器,然後檢查右向左輕掃或自左向右輕掃,並在特定條件下添加你的邏輯。

+0

你能顯示代碼嗎? – user4152 2014-11-05 12:32:00

+0

此鏈接對您有用[滑動活動](http://androidexample.com/Swipe_screen_left__right__top_bottom/index.php?view=article_discription&aid=95&aaid=118) – user3864262 2014-11-06 09:45:50