android 瀑布流 AndroidStaggeredGrid

开源项目:https://github.com/etsy/AndroidStaggeredGrid
分享一下我用过之后,觉得最关键的地方。
在给出的demo中有一个集合,记录每个位置的HeightRatio。设置Dyn/amicHeightTextView和DynamicHeightImageView的HeightRatio来控制显示的高度。
比如在DynamicHeightImageView中有一段代码来设置imageview的显示高度:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mHeightRatio > 0.0) { // set the image views size int width = MeasureSpec.getSize(widthMeasureSpec); int height = (int) (width * mHeightRatio); setMeasuredDimension(width, height); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 了解这几点之后,就能够显示出高低不一样的图片效果

你可能感兴趣的:(android 瀑布流 AndroidStaggeredGrid)