-2
A
回答
0
您可以使用這些真棒庫,將滿足您的工作。
1-對於ListView的
對於RecyclerView
執行情況回收站查看
步驟1。在JitPack庫添加到您的構建文件
repositories {
maven {
url "https://jitpack.io"
}
}
步驟2。添加依賴
dependencies {
compile 'com.github.kanytu:android-parallax-recyclerview:v1.7'
}
用法 (示例項目 - https://github.com/kanytu/example-parallaxrecycler)
創建對象列表,並把它傳遞給
ParallaxRecyclerAdapter
List<String> myContent = new ArrayList<String>(); // or another object list ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<String>(content) { @Override public void onBindViewHolderImpl(RecyclerView.ViewHolder viewHolder, ParallaxRecyclerAdapter<String> adapter, int i) { // If you're using your custom handler (as you should of course) // you need to cast viewHolder to it. ((MyCustomViewHolder) viewHolder).textView.setText(myContent.get(i)); // your bind holder routine. } @Override public RecyclerView.ViewHolder onCreateViewHolderImpl(ViewGroup viewGroup, final ParallaxRecyclerAdapter<String> adapter, int i) { // Here is where you inflate your row and pass it to the constructor of your ViewHolder return new MyCustomViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.myRow, viewGroup, false)); } @Override public int getItemCountImpl(ParallaxRecyclerAdapter<String> adapter) { // return the content of your array return myContent.size(); } };`
構造函數現在我們設置視差頭。您還需要傳遞
RecyclerView
以實現滾動偵聽器。myAdapter.setParallaxHeader(LayoutInflater.from(this).inflate(R.layout.myParallaxView, myRecycler, false), myRecyclerView);
還有一些其他的監聽器可以實現:
// Event triggered when you click on a item of the adapter.
void onClick(View v, int position);
// Event triggered when the parallax is being scrolled.
void onParallaxScroll(float percentage, float offset, View parallax);
相關問題
- 1. html佈局 - 水平滾動
- 2. iOS 6.0 +自動佈局+橫向模式導航欄+高度減少
- 3. 隱藏物體時不會減少的物體高度 - Android佈局
- 4. 如何減少網頁的高度(避免過多的滾動)
- 5. Collectionviewcell自動佈局高度,動態高度,內容高度
- 6. 減少HTML表格行高度
- 7. Android百分比佈局寬度和高度應該指定
- 8. 減少行序列在該R長度
- 9. 增加圖高度,滾動型這裏使用自動佈局
- 10. 減少底板的高度
- 11. 使頁腳高度減少?
- 12. HTML水平滾動條的高度是多少?
- 13. 水平滾動標題欄佈局
- 14. 水平滾動列布局面板
- 15. 設置水平滾動視圖佈局
- 16. Android佈局 - 雙水平滾動視圖
- 17. 水平滾動查看和佈局 - Android
- 18. 自動佈局和滾動型寬度
- 19. CSS佈局高度
- 20. UILabel自動佈局高度動畫
- 21. 減少場景高度/寬度並將畫布放入div
- 22. 滾動時減少TableViewController中的圖像
- 23. 滾動佈局
- 24. 巨大的滾動視圖佈局減慢了應用程序
- 25. Dropzone固定高度水平滾動
- 26. 水平滾動100%圖像高度
- 27. 滾動時UITableView與自動佈局不平滑
- 28. 100%的高度表的佈局,滾動欄
- 29. 關於100%高度和滾動條的佈局問題-Y
- 30. 帶有100%高度和滾動條的IE6「框架」佈局
感謝的答案,但我必須做出可點擊「同步」按鈕 –
有偵聽單擊回收站的視差頭查看'void onClick(View v,int position);' –