Giter Site home page Giter Site logo

tvrecyclerview's Introduction

TvRecyclerView

A custom RecyclerView for Android TV end.中文说明 1

ScreenShot





Usage

1.First you can add gradle dependency with command :

dependencies {
    ......
    compile 'com.henryblue.library:tvrecyclerview:1.0.8'
   }

To add gradle dependency you need to open build.gradle (in your app folder,not in a project folder) then copy and add the dependencies there in the dependencies block;

2.Add TvRecyclerView in your layout

<app.com.tvrecyclerview.TvRecyclerView
        android:id="@+id/tv_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="580dp"
        app:focusDrawable="@drawable/default_focus"/>

3.Set the LayoutManager and Adapter

 mTvRecyclerView = (TvRecyclerView) findViewById(R.id.tv_recycler_view);
 GridLayoutManager manager = new GridLayoutManager(NormalFocusActivity.this, 3);
 manager.setOrientation(LinearLayoutManager.HORIZONTAL);
 mTvRecyclerView.setLayoutManager(manager);

 int itemSpace = getResources().
                getDimensionPixelSize(R.dimen.recyclerView_item_space);
 mTvRecyclerView.addItemDecoration(new SpaceItemDecoration(itemSpace));
        
 NormalAdapter mAdapter = new NormalAdapter(this);
 mTvRecyclerView.setAdapter(mAdapter);

 mTvRecyclerView.setOnItemStateListener(new TvRecyclerView.OnItemStateListener() {
      @Override
      public void onItemViewClick(View view, int position) {
          Log.i(TAG, "you click item position: " + position);
      }

      @Override
      public void onItemViewFocusChanged(boolean gainFocus, View view, int position) {
      }
 });
 mTvRecyclerView.setSelectPadding(35, 34, 35, 38);

XML attributes

    <app.com.tvrecyclerview.TvRecyclerView
        ...
        app:scrollMode="followScroll"
        app:isAutoProcessFocus="false"
        app:focusScale="1.04f"
        app:focusDrawable="@drawable/default_focus"
        ...
        />
Name Type Default Description
scrollMode enum normalScroll Set the way to slide
isAutoProcessFocus boolean true Sets the focus of the control
focusScale Float 1.04f Set the focus scale. If 'isAutoProcessFocus' is true, this property has no effect, always equal 1.0f
focusDrawable reference null set focus drawable, If 'isAutoProcessFocus' is true, this property has no effect

Public Methods

Name Description
setSelectedScale(float) change value of focusScale
setIsAutoProcessFocus(boolean) sets the focus of the control
setFocusDrawable(Drawable) sets the focus of the drawable
setItemSelected(int) sets the position of item gets focus
setSelectPadding(int,int,int,int) sets the focus of the drawable padding, make the drawable include item

Note: Because I extended RecyclerView you can use all RecyclerView public methods too.

License

Copyright 2016 henryblue

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.

tvrecyclerview's People

Contributors

binhbt avatar henryblue avatar

Watchers

 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.