RecyclerView實現瀑布流的效果
效果圖如下
原始碼如下:
MainActivity頁面
public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private StaggeredGridLayoutManager staggeredGridLayoutManager; private MyAdapter adapter; public final static String[] imageUrls = new String[]{ "http://img.my.csdn.net/uploads/201309/01/1378037235_3453.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037235_7476.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037235_9280.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037234_3539.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037234_6318.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037194_2965.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037193_1687.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037193_1286.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037192_8379.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037178_9374.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037177_1254.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037177_6203.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037152_6352.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037151_9565.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037151_7904.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037148_7104.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037129_8825.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037128_5291.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037128_3531.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037127_1085.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037095_7515.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037094_8001.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037093_7168.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037091_4950.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949643_6410.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949642_6939.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949630_4505.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949630_4593.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949629_7309.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949629_8247.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949615_1986.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949614_8482.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949614_3743.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949614_4199.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949599_3416.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949599_5269.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949598_7858.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949598_9982.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949578_2770.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949578_8744.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949577_5210.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949577_1998.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949482_8813.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949481_6577.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949480_4490.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949455_6792.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949455_6345.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949442_4553.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949441_8987.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949441_5454.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949454_6367.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949442_4562.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037235_3453.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037235_7476.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037235_9280.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037234_3539.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037234_6318.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037194_2965.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037193_1687.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037193_1286.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037192_8379.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037178_9374.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037177_1254.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037177_6203.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037152_6352.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037151_9565.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037151_7904.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037148_7104.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037129_8825.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037128_5291.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037128_3531.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037127_1085.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037095_7515.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037094_8001.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037093_7168.jpg", "http://img.my.csdn.net/uploads/201309/01/1378037091_4950.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949643_6410.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949642_6939.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949630_4505.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949630_4593.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949629_7309.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949629_8247.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949615_1986.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949614_8482.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949614_3743.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949614_4199.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949599_3416.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949599_5269.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949598_7858.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949598_9982.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949578_2770.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949578_8744.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949577_5210.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949577_1998.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949482_8813.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949481_6577.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949480_4490.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949455_6792.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949455_6345.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949442_4553.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949441_8987.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949441_5454.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949454_6367.jpg", "http://img.my.csdn.net/uploads/201308/31/1377949442_4562.jpg", }; @Override protected void onCreate(Bundle savedInstanceState) { //去除title requestWindowFeature(Window.FEATURE_NO_TITLE); //去掉Activity上面的狀態列 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView) findViewById(R.id.recyclerview); staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL); recyclerView.setLayoutManager(staggeredGridLayoutManager); adapter = new MyAdapter(imageUrls); recyclerView.setAdapter(adapter); } public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private String[] dataSet; public MyAdapter(String[] dataSet) { this.dataSet = dataSet; } public class ViewHolder extends RecyclerView.ViewHolder { private ImageView textview; public ViewHolder(View itemView) { super(itemView); this.textview = (ImageView) itemView.findViewById(R.id.images); } } @Override public int getItemCount() { return dataSet.length; } @Override public void onBindViewHolder(ViewHolder vh, int position) { Glide.with(vh.textview.getContext()).load(dataSet[position]).into(vh.textview); } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.griditem_layout, parent, false); ViewHolder vh = new ViewHolder(v); return vh; } } }
MainActivity.xml佈局
<android.support.constraint.ConstraintLayout 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" tools:context="com.example.zhouliu3_1.MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerview" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.constraint.ConstraintLayout>
girditem佈局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/images" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
drawable放入你網上找的圖片就可以實現瀑布流的效果
相關推薦
Android中利用RecyclerView實現瀑布流效果
RecyclerView相比於傳統的ListView,功能更加強大,使用也比較方便,因此Android官方更加推薦使用RecycleView,未來也會有更多的程式逐漸從ListView轉向RecycleView。為此,首先先來了解下RecycleView的用法。當然,最先看
RecyclerView 實現瀑布流效果
上次用RecyclerView實現了ListView的效果,這次用RecyclerView實現一個瀑布流的效果~ 先上效果圖: 是不是感覺不錯啊~ 其實很簡單~ 只要換一個佈局管理器就行了 mRecyclerView.setLayoutManager(new Sta
5.使用RecyclerView優雅的實現瀑布流效果
/** * 作者:Pich * 原文連結:http://me.woblog.cn/ * QQ群:129961195 * 微信公眾號:woblog * Github:https://github.com/lifengsofts */ 概述 從前我們想實現一個瀑布流效果是
RecyclerView的簡單使用以及實現瀑布流效果
RecyclerView 簡介 RecyclerView是support.v7包中的控制元件,可以認為是ListView和GridView的增強版,RecyclerView提供了一個耦合度更低的方式來複用ViewHolder,可以更輕鬆的實現瀑布流的效果,為增加和刪除條目提
Android RecyclerView 實現瀑布流交錯效果,並使最後一行子View高度佔滿RecyclerView
而在實現完瀑布流後,覺得滑動到底部時,最後一行的高度,沒有佔滿外部View,感覺不太好。(真正的瀑布流應該是條目數近乎無窮,可以一直載入更多) 既然是瀑布流,那麼就選用StaggeredGridLayoutManager。 mRecyclerView.s
RecyclerView實現瀑布流的效果
效果圖如下 原始碼如下: MainActivity頁面 public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private
【前端】用jQuery實現瀑布流效果
scrollto title n) 個性 避免 ive gets type turn jQuery實現瀑布流效果 何為瀑布流: 瀑布流,又稱瀑布流式布局。是比較流行的一種網站頁面布局,視覺表現為參差不齊的多欄布局,隨著頁面滾動條向下滾動,這種布局還會不斷加載數據塊並附加
原生js實現瀑布流效果 函式封裝
實現目標:實現瀑布流佈局、當滾動條滾動到一定距離時載入圖片 瀑布流佈局:結合視窗改變 定位第一行的盒子 第二行第一個盒子接到第一行最矮的盒子下面 當接完後更新最矮盒子 以此類推 滾動載入圖片:案例是用陣列物件實現圖片載入 條件是當載入到最後一張圖片一半+最後盒子的offsetTop小於等於螢
只用css實現瀑布流效果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> &
RecyclerView實現瀑布流
效果圖: Main佈局只是一個RecyclerView <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.
web頁面和小程式頁面實現瀑布流效果
小程式實現瀑布流效果,和web頁面差不多,都要經過以下步驟: 1)、載入圖片,獲取圖片的寬高度; 2)、根據頁面需要顯示幾列計算每列的寬度; 3)、根據圖片真實寬度和每列的寬度比,計算出圖片需要顯示的高度; 4)、重新對圖片進行定位 1、web頁面瀑布流效果,先看效果圖(瀑布流+無限滾動載入):
[置頂] RecyclerView實現瀑布流,圖片自適應高度
話不多說,先上效果圖 對於RecyclerView,相信大家都不陌生了,這個集listView,GridView,瀑布流效果與一身強大控制元件,漸漸地滲透在每個App.... 還是回到正題,如何讓RecyclerView裡的圖片自適應高度? 我們知道,要讓RecyclerView有瀑布流效果,R
recyclerview實現瀑布流佈局
先看效果,這裡我用的背景圖片, 首先匯入依賴 compile 'com.android.support:recyclerview-v7:26.1.0' 下面就是程式碼,首先是佈局 activity_main <RelativeLayout xmlns:a
Android中RecyclerView實現瀑布流圖片顯示
效果圖: 具體程式碼如下:(註釋很詳細,基本每句都要註釋) MainActivity.java package com.zhiyuan3g.recyclerviewwaterfall; import android.content.Intent; import an
RecyclerView 實現瀑布流及點選事件,含點選回撥的介面
RecyclerView 實現瀑布流及點選事件 public class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder> { private List
自定義ViewGroup實現瀑布流效果
今天情人節,我卻在家裡看書寫程式碼,真屌絲啊哈~ 回顧:ViewGroup的時間分發流程: dispatchTouchEvent ----- onInterceptTouchEvent----- onTouchEvent 最外層的ViewGroup首先接收到觸控事件,然後
Android使用Recycler View實現瀑布流效果
下圖是淘寶上瀑布流的一個應用場景,今天我們就來用Recycler View實現以下瀑布流效果 一:建立Activity activity中 核心程式碼為 mRvPu.setLayoutManager(new StaggeredGridLayoutManager(2,
CSS3實現瀑布流效果
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>瀑布流的純css實現</title></head><
關於RecyclerView實現瀑布流,上下滑動時item之間互換位置的問題
最近專案需求,需要RecyclerView實現瀑布流。在用 StaggeredGridLayoutManager 完成瀑布流的過程中發現一個問題:它並不像pullToRefresh 那樣是穩定的list,而是item之間頻繁交換位置,有時候甚至會出現第一列和第二列完全互
RecycleView 實現瀑布流效果
1、用as開發,在build.gradle中新增依賴 dependencies { ... compile 'com.android.support:recyclerview-v7:21.0.3' } 2、用Eclipse開發,新