Giter Club home page Giter Club logo

draggablegridview's Introduction

DraggableGridView

a drag-and-drop scrolling grid view for Android

Including in your project

To start using DraggableGridView:

  • Place libs/DraggableGridView.jar into your project’s directory and add it to the build path (www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29)

  • Add an import to the activity you’d like to use it in: import com.animoto.android.views.*;

  • Add the view to your activity’s layout XML and save it:

    <com.animoto.android.views.DraggableGridView android:id="@+id/dgv" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true">
    </com.animoto.android.views.DraggableGridView>
  • Obtain a reference to the view to use in code:

    public class DraggableGridViewSampleActivity extends Activity {
      DraggableGridView dgv;
    	
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
    
          dgv = ((DraggableGridView)findViewById(R.id.dgv));
      }
  • You’re done! You can start adding any type of view you’d like.

    TextView tv = new TextView(this);
    tv.setText("Hello world!");
    dgv.addView(tv);

Features

  • Tap and hold a view to begin moving it! Drag it between other views to rearrange them, and drop them in place.

  • Scales nicely to any screen size or resolution

  • Animates smoothly to indicate the rearrangement of children

  • Performs well, even with hundreds of children

  • Becomes scrollable when it contains more children than are visible

  • Can scroll even when a child is being dragged: just bring it to the very top or bottom

  • Easy to modify or extend!

The Sample Project

The included project is an Android version of magnetic poetry, which you may have seen covering an eccentric friend’s refrigerator. It creates an OnRearrangeListener for its DraggableGridView which manipulates an ArrayList of strings.

If you’d rather not have to separately keep track of the grid’s elements, I suggest creating your own type of View that contains any information you need about the children and collecting this information from the DraggableGridView when you need it:

String[] words = new String[dgv.getChildCount()];
for (int i = 0; i < words.length; i++)
    words[i] = ((CustomView)dgv.getChildAt(i)).word;

To Do

  • Remove scrolling timer

  • Improve performance

Notes

  • This was developed targeting Android 2.2 (API level 8), though I’m sure it can be made to work on lower versions.

  • The sample project’s main activity doesn’t handle onConfigurationChanged, so it will restart if the screen orientation changes. I’ll fix this soon, but it’s not particularly important.

  • DraggableGridView and all associated code are © 2011, Animoto Inc, available under the Apache License, Version 2.0.

  • Check us out at www.animoto.com !

draggablegridview's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.