mrklar / pageddragdropgrid Goto Github PK
View Code? Open in Web Editor NEWAn Android ViewGroup that implements a paged grid with drag'n'drop moveable items
An Android ViewGroup that implements a paged grid with drag'n'drop moveable items
Good day, I have a problem in the constructor, exemple.xml, when I connect (``ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid vylitaet error in xml,
at com.Projects.libs.gridView.DragDropGrid.onMeasure (DragDropGrid.java: 696)
at android.view.View.measure (View.java: 12723)
at android.widget.HorizontalScrollView.measureChildWithMargins (HorizontalScrollView
. Java: 1159)
at android.widget.FrameLayout.onMeasure (FrameLayout.java: 293)
at android.widget.HorizontalScrollView.onMeasure (HorizontalScrollView.java: 303)
at android.view.View.measure (View.java: 12723)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java: 4698)
at android.widget.FrameLayout.onMeasure (FrameLayout.java: 293)
at android.view.View.measure (View.java: 12723)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java: 4698)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java: 1369)
at android.widget.LinearLayout.measureVertical (LinearLayout.java: 660)
at android.widget.LinearLayout.onMeasure (LinearLayout.java: 553)
at android.view.View.measure (View.java: 12723)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java: 4698)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java: 1369)
at android.widget.LinearLayout.measureVertical (LinearLayout.java: 660)
at android.widget.LinearLayout.onMeasure (LinearLayout.java: 553)
at android.view.View.measure (View.java: 12723)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView (RenderSessionImp
l.java: 542)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render (RenderSessionImpl.jav
a: 444)
at com.android.layoutlib.bridge.Bridge.createSession (Bridge.java: 326)
at com.android.ide.common.rendering.LayoutLibrary.createSession (LayoutLibrary.java:
325)
at org.jetbrains.android.uipreview.RenderService.createRenderSession (RenderService.
java: 127)
at org.jetbrains.android.uipreview.RenderUtil.renderLayout (RenderUtil.java: 151)
at
at com.intellij.openapi.application.impl.ApplicationImpl $ 6.run (ApplicationImpl.java: 465)
at java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java: 471)
at java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java: 334)
at java.util.concurrent.FutureTask.run (FutureTask.java: 166)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java: 1110)
at java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java: 603)
at java.lang.Thread.run (Thread.java: 722)
at com.intellij.openapi.application.impl.ApplicationImpl $ 1 $ 1.run (ApplicationImpl.java: 153)
Line 696
Display display = wm.getDefaultDisplay ();
@ Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode (widthMeasureSpec);
int heightMode = MeasureSpec.getMode (heightMeasureSpec);
int widthSize = MeasureSpec.getSize (widthMeasureSpec);
int heightSize = MeasureSpec.getSize (heightMeasureSpec);
WindowManager wm = (WindowManager) getContext (). GetSystemService (Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay ();
widthSize = acknowledgeWidthSize (widthMode, widthSize, display);
heightSize = acknowledgeHeightSize (heightMode, heightSize, display);
adaptChildrenMeasuresToViewSize (widthSize, heightSize);
searchBiggestChildMeasures ();
computeGridMatrixSize (widthSize, heightSize);
computeColumnsAndRowsSizes (widthSize, heightSize);
measureChild (deleteZone, MeasureSpec.makeMeasureSpec (gridPageWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec ((int) getPixelFromDip (40), MeasureSpec.EXACTLY));
setMeasuredDimension (widthSize * adapter.pageCount (), heightSize);
}`)
Please help me, and I apologize for the bad English, in the code I have not changed anything.
If i put a mount of item in PagedDragDropGrid , how can PagedDragDropGrid Recycle view?
When i fist time set adapter in gridview object but when i update it with notifyDataSetChange gridveiw data not update
I remove by removeAllView so all view gone and not set again by adapter
gridview.removeAllViews();
customSpinneradapter.notifyDataSetChanged();
gridview.notifyDataSetChanged();
adapter.notifyAll();
This update and increse the no of view if it have more view then previous but not decrese if have less and also not change the data of any view
All is perfect good, but I don't want the remove bar, and there is no way to hide it.
I want change Animation in PagedDragDropGrid like LXReorderableCollectionViewFlowLayout. See this: https://www.youtube.com/watch?v=R2L_16XeChE .So what i suppose to do? Thank you.
please how to apply refresh for the items or reordering items?
Hi,
code works absolutely fine. I did some changes and all are good, but I am unable to move the remove bar to top of screen.
Can you help me with it please.
When i long click on item after updating my phone to kitkat, the clicked item is going to the end of the list. What should I do to fix that?
i set design in example.xml. . i try to set 20 item in one page and set margin 5dp in between each item. . but i can't set bottom and top margin in between items... Please some one give a solutions .. .. . .. .
Hi ,
when item is dragged to next page ,and dropped at that time instead of adding new view,i want to swap and next page item move to previous page.
Swapping in single screen,how can i achive the swapping in multiple pages.
thanks
When I long click on an item, then drop it immediately, it performs an onClick event. In one way or another this might be a bug? I have managed to fix this by changing the return value of DragDropGrid#onTouch(View, MotionEvent)
, instead returning false directly I changed it with super.onThouchEvent(MotionEvent)
I also noticed that when I will long click on an item near (using the emulator my mouse pointer is about 5-10dip near) the delete view (not intersected with the delete view), then drop it, the item will disappear. I have also managed to fix it by calling the touchMove(event);
on the first line of DragDropGrid#touchUp(MotionEvent)
method.
I don't know if my fixes were correct, but it managed to fix my issues.
I want to add a static Item at the end of the Gridview. This Item should not move, it will be a static image with an action to add more Items dynamically.
Any suggestions?
My application is displaying real-time data in a PDDG and if I allow it to change anything in the view hierarchy (which causes a layout) while a drag is in progress, the drag is completely messed up.
I've added a set of methods to the adapter to let the client know that a drag has started / ended. It might be better to add a listener interface and a isInDrag() method to handle the same thing, so I won't add a pull request for my changes.
I have only updated the DragDropGrid.java
and added my modifications.
I used the Item.java
object in identifying page items.
It's quite messy but I've added some comments.
I updated the animateGap();
method and added rearrangePageItems();
This is just a brute force implementation.
I haven't had time to fully investigate why DragDropGrid.acknowledgeHeightSize() was being called with a 0 height, but the fallback to using the screen dimensions is probably not the way to go: it will always generate a view that is too tall, and for multi-pane layouts it will be too wide as well.
Hi How can I get the item when I click that? so far I can only get the currentPage but I can't get the item index
most adapter have notifyDataSetChanged() to notify viewgroup to refresh
this PagedDragDropGrid notifyDataSetChanged to refresh not adapter
It's wired.
Hey all, how do you implement one page, which will be on the item is 10-20, but the visible part is only 3, and you can just scroll through them without having to switch to the page.That there was one common Pag.
Thank you.
HI, I would like to know, how can I dynamically insert new item to a grid? I many solutions, but they didn't work for me.
Thanks
There are a few places where I'm modifying the data my adapter is using, and I wish to display this new data.
There doesn't appear to be any way to call notifyDataSetChanged() on the adapter or the GridView.
Any ideas on how to get the updated data to be displayed?
1.version 0.2 if I set columntCount to 3 then I must set rowCount to 3 or it not work!
still AUTOMATIC, and if 20 rows and 20 columns, the item of view is very small and not wrap content !
2.if i set > 35 items in one page then i can't see 36/37/38......
Example Demo
How should I do?
I have a question out on SO currently, but I'll also add an issue here.
I've added selectors to highlight a clicked view to provide better feedback to the user, but for some reason all the views are highlighted instead of just the clicked one.
Edit: Some progress has been made, with this answer, but it creates other problems.
If grid item are in big size paged is not scrollable properly , some view are cut in the buttom.
Please help me.
How do I catch the drop event?
Would it be possible to use this vertically (without left/right pages)? I have changed PagedDragDropGrid to extend ScrollView, but I have a bit of a problem with how it computes the height of the view.
Hello,I find a problem existing in the project:for example, if some items displayed as the order:
"item 1, item 2, item 3, item 4, item 5, item 6, item 7"
When I move the item 7 to the position between item 2 and item 3, the items become disordered. It's not "item 1, item 2, item 7, item 3, item 4, item 5, item 6". In fact, according to the source code, I find that when item 7 is moved, it is changed with the view item7 goes by and I think it's not reasonable.
I hope the logic will be like the logic in https://github.com/thquinn/DraggableGridView. Can you sove this problem kindly?
Hi! how can I make a vertical scrolling? if it is not currently possible then tell me what and how to modify?
when I long press a child and hover it over others it is shown beneath those child which are generated before, while I want it to be on top of all. I am using swap on touch up rather than on move, so this become a quite critical. I used .bringtofont() method, but no success.
Please help
how can i set an exactly height to a DragDropGrid?
After merge #47 that fixed issue #41 I can't add new items after adapter is set. You can simply modify current pageddragdropgrid-examples project to see this issue. Before merging #47 this code was working perfectly
1 Remove adding pages and items from ExamplePagedDragDropGridAdapter constructor
2 Add new method to ExamplePagedDragDropGridAdapter
public void addItem(final Item item) {
boolean added = false;
for (final Page page : pages) {
if (page.getItems().size() < rowCount() * columnCount()) {
page.addItem(item);
added = true;
break;
}
}
if (!added) {
final Page page = new Page();
page.addItem(item);
pages.add(page);
}
gridview.notifyDataSetChanged();
}
3 Change row count and column count from AUTOMATIC to ex. 3
4 In ExampleActivity at the end of onCreate() method add
adapter.addItem(new Item(1, "item1", R.drawable.ic_launcher));
adapter.addItem(new Item(2, "item2", R.drawable.ic_launcher));
5 Exception is thrown
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at ca.laplanete.mobile.pageddragdropgrid.DragDropGrid.layoutAChild(DragDropGrid.java:1005)
at ca.laplanete.mobile.pageddragdropgrid.DragDropGrid.layoutPage(DragDropGrid.java:993)
at ca.laplanete.mobile.pageddragdropgrid.DragDropGrid.onLayout(DragDropGrid.java:977)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.HorizontalScrollView.onLayout(HorizontalScrollView.java:1474)
at ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid.onLayout(PagedDragDropGrid.java:234)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:690)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Any idea?
//edit
@anlosar Since you are author of KitKat fix, maybe you know how to fix this?
Hi, How can I be noticed that the paged are scrolled ?
I was not able to add more than 24 items in one page. Plus, the scroll always sticks to the top part so it doesn't let you scroll down.
Hello Sir,
Thanks for this the best library. Sir I am quite confused for drag event, from your Conversion I got that swapItems() is fired at last. Am I right? Let me inform if I am wrong. When I have draged item from Page1 to page 3 The item show perfect as on 3rd page but when I check with this method
public void swapItems(int pageIndex, int itemIndexA, int itemIndexB) {
getPage(pageIndex).swapItems(itemIndexA, itemIndexB);
for (Page page : pages) {
for (Item item : page.getItems()) {
Log.d("Item:"+item.getItemId(), item.getName());
}
}
}
My log shows me wrong output. Dragged item is showing with page 2 I mean Wrong position.My purpose is to stored item position in database. Suggest me what I mad mistake?
Thanks
Hi, I was wondering how to impose a max number of children per page, so that if I try to drag a child to an already "full" page, that page will overflow excess children to the next page(s).
Is this already handled?
Thanks :)
How can i get rid of the extra space around each item? It seems a default behaviour that i cannot override from my xml layout. In GridView I think this can be done with the property android:listSelector="@android:color/transparent".
Any ideas? Thanks in advance.
Hi,
I would like to populate a page with relative layouts that have various sizes (for example, to have four items/views/buttons with various sizes on one or more pages).
I know that I can set layouts params in ExamplePagedDragDropGridAdapter like:
public View view(int page, int index) {
Item item = getItem(page, index);
RelativeLayout layout = new RelativeLayout(context);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(250, 250);
if (item.getName() == "v4")
{
layoutParams = new RelativeLayout.LayoutParams(500, 250);
}
else if (item.getName() == "v2")
{
layoutParams = new RelativeLayout.LayoutParams(500, 500);
}
else
{
layoutParams = new RelativeLayout.LayoutParams(250, 250);
}
ImageView buttonOn = new ImageView(context);
buttonOn.setImageResource(item.getDrawableButtonOn());
buttonOn.setPadding(0, 0, 0, 0);
buttonOn.setLayoutParams(layoutParams);
buttonOn.setTag("buttonOn");
.
.
.
layout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layout.addView(buttonOn);
return layout;
}
but DragDropGrid.java calculate the biggest child (item/button/view) and set columns and rows size according to child's dimensions. So the question is: how to set different row and column size for each page or just get rid of columns and rows and populate all pages with items like in one big cell, but capable of dragging items, swap them, moving to next page and any other features provided by this framework.
Thanks in advance
Hello, How can I get itemId when I click on item on gridview
SOLVED SEE BELOW:
I fixed it. During your longClick method you handle jiggling the itmes and start the dragged and movingView. Then in your touchMove method you handle moving the dragged view (clear animation, start animation) and you manage swapping, edges, and delete. However, this is all fine and dandy (starting animation, stopping animation) until nothing in the parent view ( "this" ) is animating, thus stopping all drawing. So if no redraw is called, you get artifacts. To fix this simple add one line (like most problems =P) to invalidate "this" before handling animation and events. Below is the new touchMove()
private void touchMove( MotionEvent event )
{
if ( movingView && aViewIsDragged() )
{
lastTouchX = (int) event.getX();
lastTouchY = (int) event.getY();
invalidate();
moveDraggedView( lastTouchX, lastTouchY );
manageSwapPosition( lastTouchX, lastTouchY );
manageEdgeCoordinates( lastTouchX );
manageDeleteZoneHover( lastTouchX, lastTouchY );
}
}
If you'd like I'll make a pull request, add the one line (and the ability to disable the remove bar) and request a merge. Thanks!
When you move an item around, it leaves behind a trial. Here is my xml:
<ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
And I have 2 pages, 4 items in each, both pages are 2 x 3 allowing for 6 items max per page.
When you move the items slowly from the top down, or near the edges, you get artifacts. And if you have only 1 item on a page it leaves a ton of trailing artifacts...
Hi,
When trying to add more items to a page than the screen can show there is no possible way to view the un-viewed items.
Am I missing something? I tried to change DragDropGrid to extend ScrollView but it still only showed half.
I changed the example to have only one page, with 300 items, only ~130 were viewable+scrolling in a GalaxyTab 2 and only ~30 in a Samsung Galaxy Ace.
Thanks
Hi,
I have slowed down the translation animation to a duration of 2500. Now my problem is that when I move an item over other is swapping properly, but if I release it in between the translate animation, it doesn't complete the animation, but just updates the new view with a jerk. But I want it to complete the animation if if I have released my finger from screen
Please help.
Dear mrKlar,
Thank you for sharing you knowledge with all of us.
But I have encounter vertical scrolling problem, I have read everybody's problems in the different comments, and I haven't found a solution. I know you are working on your spare time on it, but I would like to ask you for help.
My code have got just one page, and I want to add vertical scrolling in it, it is easier than adding it to several pages. I would appreciate if you could tell me what I should do.
Please help me,
Thank you.
I want to have Grid View as Horizontal Scroll View with scroll bar if over flow. As far as i understand, Right now i can control layout of each item but, I'm sure how to change complete layout to Horizontal layout. I want to have a single line Grid with Scroll and allow user to re arrange elements in single line grid.
If Grid view comes with columns and row configurable like, set no.of columns or rows to 2 or 3 that wold be fantastic.
is this possible? been trying to do this im getting null pointer exception
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.