LightSun / android-drag-FlowLayout
- вторник, 16 августа 2016 г. в 03:14:36
Java
this is a draggable flow layout lib.
this is a draggable flow layout lib.
mDragflowLayout.setOnItemClickListener(new DragFlowLayout.OnItemClickListener() {
@Override
public boolean performClick(DragFlowLayout dragFlowLayout, View child,
MotionEvent event, int dragState) {
//检查是否点击了关闭按钮(iv_close控件)。点击了就删除
//ViewUtils.isViewUnderInScreen 判断点击事件是否是你需要的.
//dragState 是拖拽状态。
boolean performed = dragState != DragFlowLayout.DRAG_STATE_IDLE
&& ViewUtils.isViewUnderInScreen(child.findViewById(R.id.iv_close),
(int) event.getRawX(),(int) event.getRawY());
if(performed){
dragFlowLayout.removeView(child);
}
//点击事件
return performed;
}
});
//预存指定个数的Item. 这些Item会反复使用
mDragflowLayout.prepareItemsByCount(10);
mDragflowLayout.setOnItemClickListener(new DragFlowLayout.OnItemClickListener() {
@Override
public boolean performClick(DragFlowLayout dragFlowLayout, View child,
MotionEvent event, int dragState) {
//检查是否点击了关闭按钮(iv_close控件)。点击了就删除
//ViewUtils.isViewUnderInScreen 判断点击事件是否是你需要的.
//dragState 是拖拽状态。
boolean performed = dragState != DragFlowLayout.DRAG_STATE_IDLE
&& ViewUtils.isViewUnderInScreen(child.findViewById(R.id.iv_close),
(int) event.getRawX(),(int) event.getRawY());
if(performed){
dragFlowLayout.removeView(child);
}
//点击事件
return performed;
}
});
mDragflowLayout.setDragAdapter(new DragAdapter<TestBean>() {
@Override
public int getItemLayoutId() {
return R.layout.item_drag_flow;
}
@Override
public void onBindData(View itemView, int dragState, TestBean data) {
itemView.setTag(data);
TextView tv = (TextView) itemView.findViewById(R.id.tv_text);
tv.setText(data.text);
//iv_close是关闭按钮。只有再非拖拽空闲的情况吓才显示
itemView.findViewById(R.id.iv_close).setVisibility(
dragState!= DragFlowLayout.DRAG_STATE_IDLE
&& data.draggable ? View.VISIBLE : View.INVISIBLE);
}
@NonNull
@Override
public TestBean getData(View itemView) {
return (TestBean) itemView.getTag();
}
});
//数据实体实现IDraggable 接口,并且 isDraggable 为false即可
private static class TestBean implements IDraggable{
String text;
boolean draggable = true;
public TestBean(String text) {
this.text = text;
}
@Override
public boolean isDraggable() {
return draggable;
}
}
compile 'com.heaven7.android.dragflowlayout:dragflowlayout:1.0.6'
现在是用弹出窗体做的,下个版本将考虑用单独的普通view来做, 拖拽效果应该会更好些。
i like technology. especially the open-source technology.And previous i didn't contribute to it caused by i am a little lazy, but now i really want to do some for the open-source. So i hope to share and communicate with the all of you.
Copyright 2016
heaven7(donshine723@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.