Git Product home page Git Product logo

swipestack's Introduction

SwipeStack

A simple, customizable and easy to use swipeable view stack for Android.

Download License Apache Android Arsenal

Demo screen 1 Demo animation Demo screen 2

QuickStart

Include the Gradle dependency

dependencies {
    compile 'link.fls:swipestack:0.3.0'
}

Use it in your layout file

  1. Use the link.fls.swipestack.SwipeStack view in your XML layout file
  2. Set the parent view's clipChildren attribute to false

Example:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false">

    <link.fls.swipestack.SwipeStack
        android:id="@+id/swipeStack"
        android:layout_width="320dp"
        android:layout_height="240dp"
        android:padding="32dp"/>

</FrameLayout>

Create an adapter

Create an adapter which holds the data and creates the views for the stack.

Example:

public class SwipeStackAdapter extends BaseAdapter {

    private List<String> mData;

    public SwipeStackAdapter(List<String> data) {
        this.mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public String getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = getLayoutInflater().inflate(R.layout.card, parent, false);
        TextView textViewCard = (TextView) convertView.findViewById(R.id.textViewCard);
        textViewCard.setText(mData.get(position));

        return convertView;
    }
}

Assign the adapter to the SwipeStack

Last, but not least, assign the adapter to the SwipeStack.

Example:

SwipeStack swipeStack = (SwipeStack) findViewById(R.id.swipeStack);
swipeStack.setAdapter(new SwipeStackAdapter(mData));

That's it!

Callbacks

Currently SwipeStack implements the following callbacks:

  • the SwipeStackListener notifies you when a view was swiped to the left / right or when the stack becomes empty.
  • the SwipeProgressListener notifies you about the progress when the user starts / stops dragging a view around.

Attributes

All attributes are optional.

allowed_swipe_directions specifies the allowed swipe directions. Default: both

animation_duration specifies the duration of the animations. Default: 300ms

stack_size specifies the maximum number of visible views. Default: 3

stack_spacing specifies the vertical distance between two views. Default: 12dp

stack_rotation specifies the maximum random ratation (in degrees) of a card on the stack. Default: 8

swipe_rotation specifies the rotation (in degrees) of the view when it gets swiped left / right. Default: 15

swipe_opacity specifies the opacity of the view when it gets swiped left / right. Default: 1.0

scale_factor specifies the scale factor of the views in the stack. Default: 1.0

disable_hw_acceleration set to true disables hardware acceleration. Default: false

Copyright Notice

Copyright (C) 2016 Frederik Schweiger

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

swipestack's People

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.