https://github.com/huxq17/handygridview
HandyGridView是一个高仿支付宝,网易新闻的高性能的标签可拖动排序的GridView。
https://github.com/huxq17/handygridview
android-ui drag-and-drop gridview handygridview
Last synced: about 1 year ago
JSON representation
HandyGridView是一个高仿支付宝,网易新闻的高性能的标签可拖动排序的GridView。
- Host: GitHub
- URL: https://github.com/huxq17/handygridview
- Owner: huxq17
- License: apache-2.0
- Created: 2017-11-10T09:30:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-11T14:51:42.000Z (over 6 years ago)
- Last Synced: 2025-03-30T05:11:24.298Z (about 1 year ago)
- Topics: android-ui, drag-and-drop, gridview, handygridview
- Language: Java
- Homepage:
- Size: 1.21 MB
- Stars: 280
- Watchers: 6
- Forks: 29
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HandyGridView
[]( https://android-arsenal.com/details/1/6571 )
HandyGridView本质上是一个GridView,所以你也可以当成普通的GridView来使用,HandyGridView继承了GridView并在此之上添加了item拖动和交换,绘制图文等功能。
由于只是一个GridView,所以性能比目前其他大部分解决方案都要好。
HandyGridView is a high-performance drag and drop GridView, it extends GridView, you can drag drop GridView item to sort the labels,and draw something on the GridView. Just use the HandyGridView like a GridView.
---
### Screenshots

---
### Usage
#### Gradle
```groovy
dependencies {
compile 'com.huxq17.handygridview:handygridview:1.2.0'
}
```
#### minSdkVersion 11
#### HandyGridView's three modes:
Mode | introduction
---|---
TOUCH | Edit mode,the item can be dragged
LONG_PRESS | Long press mode,item can be dragged after long press.
NONE | Item can not be dragged, jsut like normal GridView.
Usage:
```
HandyGridView#setMode(TOUCH|LONG_PRESS|NONE);
```
#### Adapter
HandyGridView会在item被拖动交换时发出通知,如果想要做出对应数据上的变化,则可以在Apdater中实现OnItemMovedListener,示例如下:
HandyGridView will send a notification to notify you swip the data source when its item's order is changed. the usage is as follows:
```
public class GridViewAdapter extends BaseAdapter implements OnItemMovedListener{
@Override
public void onItemMoved(int from, int to) {
String s = mDatas.remove(from);
mDatas.add(to, s);
}
@Override
public boolean isFixed(int position) {
//When postion==0,the item can not be dragged.
if (position == 0) {
return true;
}
return false;
}
}
```
#### 绘制图文
HandyGridView提供了在gridview上绘制图文的接口,示例如下:
You can draw something on HandyGridView, the usage is as follows:
```
mGridView.setDrawer(new IDrawer() {
@Override
public void onDraw(Canvas canvas, int width, int height) {
if (!mGridView.isNoneMode()) {
int offsetX = -DensityUtil.dip2px(MainActivity.this, 10);
int offsetY = -DensityUtil.dip2px(MainActivity.this, 10);
//文字绘制于gridview的右下角,并向左,向上偏移10dp。
//Draw text on the right-bottom of GridView.
drawTips(canvas, width + offsetX, height + offsetY);
}
}
},false);
private void drawTips(Canvas canvas, int width, int height) {
if (mTextPaint == null) {
mTextPaint = new TextPaint();
mTextPaint.setColor(Color.parseColor("#CFCFCF"));
mTextPaint.setTextSize(DensityUtil.dip2px(MainActivity.this, 12));
Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
textHeight = (int) (fontMetrics.bottom - fontMetrics.top) + 1;
textWidth = (int) mTextPaint.measureText(paintText) + 1;
}
width = width - textWidth;
height = height - textHeight;
if (tipsLayout == null) {
tipsLayout = new StaticLayout(paintText, mTextPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.5f, 0f, false);
}
canvas.translate(width, height);
tipsLayout.draw(canvas);
}
```
以上就是主要的用法了,[更多的用法可以参考example](https://github.com/huxq17/HandyGridView/blob/master/app/src/main/java/com/handygridview/example/MainActivity.java).
The above is the main usage,[click to get more](https://github.com/huxq17/HandyGridView/blob/master/app/src/main/java/com/handygridview/example/MainActivity.java).
---
### 更新日志
2018-8-29:
1.解决HandyGridView在没有item并且horizontalSpacing为0dp或者没有设置时触摸会挂掉的问题
2017-12-29:
1.解决某些小米手机上item拖动交换时会闪烁的问题,更新到1.1.0
---
### LICENSE
[Apache License 2.0](LICENSE)