Giter VIP home page Giter VIP logo

draggableview's Introduction

DraggableView

DraggableView is an Android library to make floating draggable view easy, currently it only extends from ImageView. Now you can make any view (or viewgroup) draggable using extensions on Kotlin & provided utils class on Java

Preview

Setup

On root / project build.gradle file add maven { url 'https://jitpack.io' }

Example:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

On app build.gradle add implementation 'com.github.hyuwah:DraggableView:LatestVersion'

Example:

dependencies {
    ...
    implementation 'com.github.hyuwah:DraggableView:LatestVersion'
    ...
}

Note: check the number on Jitpack badge above for latest version

Usage

Customizable Attributes

DraggableImageView

Attribute Value (Default) XML Code
Animate true, false (false) animate setAnimate(boolean isAnimate)
Sticky Axis NON_STICKY, STICKY_AXIS_X, STICKY_AXIS_Y, STICKY_AXIS_XY (NON_STICKY) sticky setStickyAxis(int axis)

Basic sample

Using xml view (DraggableImageView)

On Layout XML file

<io.github.hyuwah.draggableviewlib.DraggableImageView
            android:src="@mipmap/ic_launcher_round"
            android:id="@+id/draggableView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

On Activity / Fragment file

var dv = findViewById<DraggableImageView>(R.id.draggableView)
dv.setOnClickListener {
    // TODO on click
}

Using extension (Kotlin only)

You can extent any view or viewgroup to be draggable (i.e. Button, FrameLayout, Linearlayout, LottieView, etc)

Here's some example using TextView:

<TextView
            android:id="@+id/tv_test_draggable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="DRAG ME!" />
var tv = findViewById<TextView>(R.id.tv_test_draggable)

tv.makeDraggable(Draggable.STICKY.AXIS_X, true) // default is STICKY.NONE & animated true

// First param is the axis:
// - Draggable.STICKY.AXIS_X
// - Draggable.STICKY.AXIS_Y
// - Draggable.STICKY.AXIS_XY
// - Draggable.STICKY.NONE

// Second param is animation toggle
// - true or false

Using DraggableUtils (on Java)

If you're on java class, you could do it with the help of DraggableUtils

Here's some example using Button:

<Button
            android:id="@+id/tv_test_draggable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="DRAGGABLE BUTTON!" />
Button button = findViewById(R.id.tv_test_draggable);

DraggableUtils.makeDraggable(button, Draggable.STICKY.AXIS_X, true); // default is STICKY.NONE & animated true

// First param is the view

// Second param is the axis:
// - Draggable.STICKY.AXIS_X
// - Draggable.STICKY.AXIS_Y
// - Draggable.STICKY.AXIS_XY
// - Draggable.STICKY.NONE

// Third param is animation toggle
// - true or false

Check example module kotlin, java for actual implementation

Accompanying Article

License

DraggableView is available under the MIT license. See the LICENSE file for more info.

draggableview's People

Contributors

hyuwah 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.