GithubHelp home page GithubHelp logo

yangzhanlong / limitscrollerview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openxu/limitscrollerview

0.0 2.0 0.0 5.06 MB

自定义控件——高仿天猫轮转广告条,可指定每次展示的广告条数,滚动速度、滚动时间间隔

Java 100.00%

limitscrollerview's Introduction

###高仿天猫轮转广告条,可指定每次展示的广告条数,滚动速度、滚动时间间隔

###讲解博客:http://blog.csdn.net/xmxkf/article/details/53303872

##效果图:

##使用方法:

1、文件拷贝: ①、将limit_scroller.xmllimit_scroller_item.xml拷贝到layout文件夹中 ②、将attrs.xml拷贝到values目录下 ③、将LimitScrollerView自定义控件拷贝到项目源码目录下

2、在activity布局中使用自定义控件

    <com.openxu.lc.LimitScrollerView
      android:id="@+id/limitScroll"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      openxu:limit="2"
      openxu:durationTime="3000"
      openxu:periodTime="5000"/>

3、Activity中: ①、初始化控件

  limitScroll = (LimitScrollerView)findViewById(R.id.limitScroll);

②、设置数据适配器,需要实现LimitScrollerView.LimitScrllAdapter,详情请见MainActivity.MyLimitScrllAdapter

    //API:1、设置数据适配器
    adapter = new MyLimitScrllAdapter();
    limitScroll.setDataAdapter(adapter);

③、请求到服务器数据后填充数据

    adapter.setDatas(datas);

④、同步生命周期方法 onStart()方法中调用

  //API:2、开始滚动
  limitScroll.startScroll();    

onStop()方法中调用

  //API:3、停止滚动
  limitScroll.cancel();  

⑤、条目点击事件

  //API:4、设置条目点击事件
  limitScroll.setOnItemClickListener(new LimitScrollerView.OnItemClickListener() {
      @Override
      public void onItemClick(Object obj) {
          if(obj instanceof DataBean){
              //强制转换
              DataBean bean = (DataBean)obj;
              Toast.makeText(MainActivity.this, "点击了:"+bean.getText(), Toast.LENGTH_SHORT).show();
              Log.v("oepnxu", "点击了:"+bean.getText());
          }

      }
  });

limitscrollerview's People

Contributors

openxu avatar

Watchers

James Cloos avatar miemie 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.