FluidGridAdapter
An Android listview adapter that arranges images in a fluid grid.
Install / Use
/learn @bmull/FluidGridAdapterREADME
FluidGridAdapter
A listview adapter that arranges images in a fluid grid. Callbacks for loading the image into the view and for when a single cell is tapped. Allows for custom cell padding, row height, and cell background.
| Display a grid of photos | Adjust padding and row height | Set the cell background color |
| --------------------------- | -------------------------------- | ------------------------------------ |
|
|
|
|
Example Usage
Create a FluidGridAdapter by passing in an array of objects that have:
- an image url/tag/identifier
- an aspect ratio OR width & height
Here's using an example using a library such as Picasso
<pre> //////////////////////////////////////////////////////////////////////////////// //Query the MediaStore for device photos and build an array of ImageData objects //////////////////////////////////////////////////////////////////////////////// String[] projection = { MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails.DATA, MediaStore.Images.Thumbnails.HEIGHT, MediaStore.Images.Thumbnails.WIDTH }; Cursor cursor = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); ArrayList<ImageData> imageDatas = new ArrayList<ImageData>(); int photoHeightIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.HEIGHT); int photoWidthIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.WIDTH); int fileLocationIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); while(cursor.moveToNext()) { int photoHeight = cursor.getInt(photoHeightIndex); int photoWidth = cursor.getInt(photoWidthIndex); String fileLocation = cursor.getString(fileLocationIndex); if(photoWidth > 0 && photoHeight > 0) { ImageData imageData = new ImageData(fileLocation, photoWidth, photoHeight); imageDatas.add(imageData); } } ///////////////////////////////////////////////////////// //Pass the array of ImageData objects into the adapter ///////////////////////////////////////////////////////// FluidGridAdapter fluidGridAdapter = new FluidGridAdapter(this, imageDatas){ @Override protected void onSingleCellTapped(ImageData imageData) { Log.d(TAG,"Single cell tapped"); } @Override protected void loadImageIntoView(String photoUrl, int cellWidth, int cellHeight, ImageView imageHolder) { Picasso.with(context).load(photoUrl).resize(cellWidth, cellHeight).into(imageHolder); } }; listview.setAdapter(fluidGridAdapter); </pre>Compatibility
Compatible and tested with Android 4.0 and above.
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
