Coder Social home page Coder Social logo

horizontalscrollwidget's Introduction

HorizontalScrollWidget

水平滑动组件,适用于app首页金刚区.

支持特性

1.可自定义行列数;

2.支持自定义item布局;

3.数据支持分页排序;

4.支持所有常规指示器样式或自定义指示器.

效果图

安装

step 1: 项目根目录的build.gradle添加如下配置:

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

step 2: app下的build.gradle文件中添加依赖:

dependencies {
	implementation 'com.github.shijia2118:HorizontalScrollWidget:1.0.7'
}

使用

step 1:xml中添加布局:

<com.xiyou.mylibrary.HorizontalScrollWidget
        android:id="@+id/test"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        app:layout_constraintTop_toTopOf="parent"
        cus:row_spacing="15dp"
        cus:background="@drawable/card_bg_r4"
        cus:attach_to_inner="false"
        cus:padding_top="8dp"
        cus:padding_bottom="10dp"/>

step 2:自定义item的布局文件,也可以直接使用本库demo中的item_layout.xml.

step 3:自定义适配器adapter,并且继承ColumnBaseAdapter(也可以直接使用本库demo中的CustomAdapter).

step 4:java代码中使用:

//实例化组件
HorizontalScrollWidget<ColumnBean, ColumnAdapter> horizontalScrollWidget = findViewById(R.id.test);
//实例化适配器
adapter = new ColumnAdapter(MainActivity.this);
//获取数据
mDataList = DataFactory.loadData();
//链式调用
horizontalScrollWidget
	.setAdapter(adapter) //适配器
        .addOnHorizontalItemClickListener(onHorizontalItemClickListener) //item点击事件
        .setData(mDataList) //获取数据
        .setIndicator(new BaseIndicator(this)) //设置通用指示器.如果不设,默认为RoundedLinesIndicator
        .build();

注:BaseIndicator为通用指示器.可以在xml布局中通过设置不同的indicator_width,indicator_height以及radius,实现圆角矩形,矩形等不同样式指示器.默认条件下是圆点指示器.

方法

方法名 返回类型 描述
setAdapter this 设置适配器
addOnHorizontalItemClickListener this item点击事件
setIndicator this 设置指示器
getDataList List 获取数据列表
setData void 重新设置column数据

属性

Attributes format describe
columns integer 每页列数
rows integer 行数
track_color color|reference 圆角矩形指示器轨道颜色
thumb_color color|reference 圆角矩形指示器滑块颜色
scroll_bar_width dimension|reference  圆角矩形指示器轨道宽度(默认120px)
scroll_bar_height dimension|reference 圆角矩形指示器轨道高度(默认9px,同滑块高度)
radius dimension|reference 圆角矩形指示器圆角度数(默认5px)
thumb_width dimension|reference 圆角矩形指示器滑块宽度(默认40px)
attach_to_inner boolean 滚动条是否在内容里面(默认true)
background reference 背景
row_spacing dimension|reference 行间距
indicator_margin_top dimension|reference 指示器顶部边距
indicator_margin_bottom dimension|reference 指示器底部距离
padding_left dimension|reference 滑动区域左侧内边距
padding_right dimension|reference 滑动区域右侧内边距
padding_top dimension|reference 滑动区域顶部内边距
padding_bottom dimension|reference 滑动区域底部内边距
pageMode dimension|reference 分页模式。若为true,数据按行排序,排满1行,再排下一行;若为false,数据按列排序,排满1列,再排下一列。默认为true。
indicator_width dimension|reference 指示器宽度
indicator_height dimension|reference 指示器高度
indicator_radius dimension|reference 指示器圆角度数
indicator_space dimension|reference 指示器间距
open_indicator_scale dimension|reference 指示器选中后是否需要改变尺寸,默认false

具体使用请查看demo.

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.