Android瀑布流的实现
来源:互联网 发布:jq push 二维数组 编辑:程序博客网 时间:2024/06/10 04:16
/** * Created by Venn on 2016/4/18. */1 WaterFallStream public class WaterFallStream extends ScrollView { private Context mContext; private LinearLayout llWaterPool; private int columns; private List<LinearLayout> subChildList; private int childCounts; private onReachBottomListener reachBottomListener; public WaterFallStream(Context context) { this(context, null); } public WaterFallStream(Context context, AttributeSet attrs) { super(context, attrs); this.mContext = context; TypedArray ta = mContext.obtainStyledAttributes(attrs, R.styleable.WaterFallStream); columns = ta.getInt(R.styleable.WaterFallStream_columns, 1); init(); } public void setReachBottomListener(onReachBottomListener reachBottomListener) { this.reachBottomListener = reachBottomListener; } public int getColumns() { return columns; } private void init() { subChildList = new ArrayList<>(); llWaterPool = new LinearLayout(mContext); llWaterPool.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams .MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); llWaterPool.setLayoutParams(params); this.addView(llWaterPool); for (int i = 0; i < columns; i++) { LinearLayout llChild = new LinearLayout(mContext); LinearLayout.LayoutParams childParams = new LinearLayout.LayoutParams(0, ViewGroup .LayoutParams.WRAP_CONTENT, 1.0f); llChild.setOrientation(LinearLayout.VERTICAL); llChild.setLayoutParams(childParams); llWaterPool.addView(llChild); subChildList.add(llChild); } } public void addSubView(View view) { if (!subChildList.isEmpty()) { int childIndex = childCounts % columns; subChildList.get(childIndex).addView(view); childCounts++; } } @Override public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: int height = getHeight(); int scrollY = getScrollY(); int mHeight = height + scrollY; int contentHeight = llWaterPool.getHeight(); if (mHeight >= contentHeight) { if (reachBottomListener != null) { reachBottomListener.addMore(this); } } break; default: break; } return super.onTouchEvent(ev); } public interface onReachBottomListener { void addMore(WaterFallStream stream); }}
2 Style<declare-styleable name="WaterFallStream"> <attr name="columns" format="integer"></attr></declare-styleable>
3 Activitypublic class MainActivity extends Activity implements WaterFallStream.onReachBottomListener { private WaterFallStream waterFallStream; private int columns; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); waterFallStream = (WaterFallStream) this.findViewById(R.id.water_stream); waterFallStream.setReachBottomListener(this); columns = waterFallStream.getColumns(); } @Override public void addMore(WaterFallStream stream) { for (int i = 0; i < columns; i++) { ImageView imageView = new ImageView(this); switch (i % columns) { case 0: imageView.setImageResource(R.mipmap.image); break; case 1: imageView.setImageResource(R.mipmap.head); break; case 2: imageView.setImageResource(R.mipmap.image2); break; default: break; } stream.addSubView(imageView); } }}
2 0
- android 瀑布流 的实现
- Android瀑布流的实现
- 特别简单的android瀑布流实现
- Android开发--瀑布流效果的实现
- Android 瀑布流控件的实现
- 瀑布流的实现
- 瀑布流的实现
- 瀑布流的实现
- android 瀑布流的实现(用recyclerview的实现的)
- android 瀑布流图片实现
- android 瀑布流实现效果
- 【Android-RecyclerView】瀑布流实现
- 【Android-RecyclerView】瀑布流实现
- Android瀑布流实现二
- Android RecyclerView实现瀑布流
- android 瀑布流的实现详解,附源码
- [Github开源库PinterestLikeAdapterView]--Android瀑布流的实现
- Android不规则瀑布流照片墙的实现+LruCache算法
- Android 加载高清大图
- React学习总结
- 欢迎使用CSDN-markdown编辑器
- 17、责任链模式(ChainofResponsibility)
- poj 2724 最大独立集
- Android瀑布流的实现
- mfc获取自身版本号
- tcp/ip
- 接口(interface)原来是可以被继承(extends)的 2007-07-20 10:19:00
- 别人总结的牛人博客,用于自己的学习。
- Hadoop2.6.0版本MapReudce示例之WordCount(一)
- c++实现mysql数据库数据缓存
- BP神经网络中的过拟合现象
- commit 与do_key('commit_form')区别