【文件属性】:
文件名称:Android-DraggableGridViewPager-仿zaker效果的拖拽排序.zip
文件大小:1.65MB
文件格式:ZIP
更新时间:2022-10-13 21:53:51
开源项目
仿zaker效果的拖拽排序。可以动态设置列数,动态增加或者减少item,当一页填满自动增加到下一页,当页数大于1,可以左右翻页。项目地址:https://github.com/zzhouj/Android-DraggableGridViewPager 效果图: 如何使用:xml中创建
2. 为DraggableGridViewPager设置AdaptermAdapter = new ArrayAdapter(this, 0) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final String text = getItem(position);
if (convertView == null) {
convertView = (TextView) getLayoutInflater().inflate(R.layout.draggable_grid_item, null);
}
((TextView) convertView).setText(text);
return convertView;
}
};
mDraggableGridViewPager.setAdapter(mAdapter);3. 为DraggableGridViewPager设置监听器mDraggableGridViewPager.setOnPageChangeListener(new OnPageChangeListener() {//页面滚动监听
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {//页面正在滚动时触发
//System.out.println("onPageScrolled 滚动了");
}
@Override
public void onPageSelected(int position) {//由于页面滚动,导致页面发生变化
//System.out.println("onPageScrolled 页面变化了 position=" position);
}
@Override
public void onPageScrollStateChanged(int state) {//滚动时,监听滚动状态的变化
//System.out.println("onPageScrolled 滚动状态state=" state);
}
});
mDraggableGridViewPager.setOnItemClickListener(new OnItemClickListener() {//单击某一item时触发
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
showToast(((TextView) view).getText().toString());
}
});
mDraggableGridViewPager.setOnItemLongClickListener(new OnItemLongClickListener() {//长按某一item触发
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
showToast(((TextView) view).getText().toString() " long clicked!!!");
return true;
}
});
mDraggableGridViewPager.setOnRearrangeListener(new OnRearrangeListener() {//拖动导致重新排序触发
@Override
public void onRearrange(int oldIndex, int newIndex) {
System.out.println("onPageScrolled OnRearrangeListener.onRearrange from=" oldIndex ", to=" newIndex);
String item = mAdapter.getItem(oldIndex);
mAdapter.setNotifyOnChange(false);
mAdapter.remove(item);
mAdapter.insert(item, newIndex);
mAdapter.notifyDataSetChanged();
}
});
【文件预览】:
Android-DraggableGridViewPager-master
----.gitignore(332B)
----DraggableGridViewPagerTest()
--------AndroidManifest.xml(702B)
--------res()
--------src()
--------project.properties(639B)
--------.settings()
--------libs()
----LICENSE(1KB)
----README.md(5KB)
----snapshot()
--------dragging.png(157KB)
--------idle.png(155KB)
--------swipe.png(158KB)
----DraggableGridViewPager()
--------AndroidManifest.xml(398B)
--------src()
--------project.properties(584B)
--------.settings()
--------libs()
----.gitattributes(483B)