RecyclerView實現終極畫廊效果 中間突出並且壓住兩側布局


先給大家上個gif 要不然下面很枯燥

忘記原來在哪里看到了.....

 

 

這個效果我找了NNNNNN長時間,,,我認為憑我現在的能力 寫出來需要好久 所以 退而求其次找大神寫好的...

你們不要小看了這個  我整整找了三四天才找到這個一個符合的(就一個 我的蒼天)

廢話不多說直接上代碼

step 1

添加依賴 (不要問我在哪里添加)

compile'com.azoft.carousellayoutmanager:carousel:1.2.1'

 

 

step 2

布局 就用系統的就可以

 

step 3

adapter 配置  (正常寫你自己的邏輯  跟這些都沒關系  主要就是layoutmanage)

 

 

step 4

activity配置  

 

initRecyclerView()方法內容 ------關鍵地方
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

 

//實現zoom效果

// enable zoom effect. this line can be customized

layoutManager.setPostLayoutListener(newCarouselZoomPostLayoutListener());

layoutManager.setMaxVisibleItems(2);

recyclerView.setLayoutManager(layoutManager);

//固定item大小

// we expect only fixed sized item for now

recyclerView.setHasFixedSize(true);

// sample adapter with random data

recyclerView.setAdapter(adapter);

//實現中間item滾動

// enable center post scrolling

recyclerView.addOnScrollListener(newCenterScrollListener());

 

 

//item滑動監聽

DefaultChildSelectionListener.initCenterItemListener(newDefaultChildSelectionListener.OnCenterItemClickListener() {

@Override

public voidonCenterItemClicked(@NonNullfinalRecyclerViewrecyclerView,@NonNullfinalCarouselLayoutManagercarouselLayoutManager,@NonNullfinalViewv) {

final intposition= recyclerView.getChildLayoutPosition(v);

 

},recyclerView,layoutManager);

 

 

//item點擊監聽

 

layoutManager.addOnItemSelectionListener(newCarouselLayoutManager.OnCenterItemSelectionListener() {

@Override

public voidonCenterItemChanged(final intadapterPosition) {

if(CarouselLayoutManager.INVALID_POSITION!= adapterPosition) {

 

}

}

});

 

到此就可以完事了  大家回去多家聯系聯系  因為我也忘記原demo在哪里了(好像是在 IT藍豹里找的) 因為我這個是項目里的 所以我就懶得寫demo了 大家也可以試試在github上搜索  carousellayoutmanager 沒准就可以找到  之后下載demo 改一些坑就可以用了

大功告成!!!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM