Giter Site home page Giter Site logo

slidinglayout's Introduction

SlidingLayout

A library for sliding views, which is usually used in book readers.

一个针对电子书阅读的划屏库 libsliding。

Demo下载

Overview

本库的主要相关的类如下:

SlidingLayout: 用于滑动的Layout,类似ViewPager

SldingAdapter: 用于获取数据和页面展示的类,类似Android的Adapter,不过SlidingAdapter有自己的接口需要实现

Slider: 滑动方式的基类,包括PageSlider和OverlappedSlider,分别表示左右平移滑动和左右覆盖滑动。

Usage

在布局文件里加入如下的xml

<com.martian.libsliding.SlidingLayout
    android:id="@+id/sliding_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

在Java代码里获取到SlidlingLayout的实例后(设为slidingLayout), 首先设置提供内容的Adapter,Adapter需要继承SlidingAdapter实现相应的接口

slidingLayout.setAdapter(new SlidingAdapter() {...}); // 基于SlidingAdapter创建Adapter实例

然后设置滑动方式

slidingLayout.setSlider(new PageSlider()); // 左右平移滑动,类似ViewPager

或者

slidingLayout.setSlider(new OverlappedSlider()); // 左右覆盖滑动

具体用法可参照目录app下的MainActivity.java

SlidingAdapter

由于电子书内容的获取一般是顺序的获取,因此不同于Android的BaseAdapter, SlidingAdapter提供了关于next和previous的接口,具体如下:

// 通过内容实例t来创建或更新contentView,
// 若contentView为null,则创建新的view,否则更新contentView
// 返回为创建或更新后的contentView
public abstract View getView(View contentView, T t);

// 获取当前要显示的内容实例
public abstract T getCurrent();

// 获取下一个要显示的内容实例
public abstract T getNext();

// 获取前一个要显示的内容实例
public abstract T getPrevious();

// 判断当前是否还有下一个内容实例
public abstract boolean hasNext();

// 判断当前是否还有前一个内容实例
public abstract boolean hasPrevious();

// 实现如何从当前的实例移动到下一个实例
protected abstract void computeNext();

// 实现如何从当前的实例移动到前一个实例
protected abstract void computePrevious();

该库已使用在我们的小说阅读应用淘小说中,欢迎大家下载试用

slidinglayout's People

Contributors

xuzb avatar martiansutdio 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.