项目作者: seunghyukcho

项目描述 :
Recyclerview library that supports live animations and auto swipe with ViewPager
高级语言: Kotlin
项目地址: git://github.com/seunghyukcho/android-live-slider.git
创建时间: 2019-07-16T13:30:58Z
项目社区:https://github.com/seunghyukcho/android-live-slider

开源协议:Apache License 2.0

下载


Android Live Slider

Build Status
Jitpack
Downloads
License

Awesome Recyclerview library that supports live animations and auto swipe with ViewPager.

Requirements

  • Minimum SDK Version : 24
  • Recommended SDK Version : 29

Preview

Getting Start

Dependency Setting

Step 1. Add the JitPack repository in your root project’s build.gradle file :

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Step 2. Add our library dependency on your project build.gradle file.

  1. dependencies {
  2. implementation 'com.github.shhj1998:android-live-slider:Tag'
  3. }

Implementation

Step 1. Create a ViewPager layout like example_page.xml which will be inside your ViewPager :

  1. <FrameLayout
  2. android:id="@+id/page"
  3. ...>
  4. <ImageView
  5. android:id="@+id/image"
  6. ...></ImageView>
  7. <TextView
  8. android:id="@+id/title"
  9. android:text="Title"
  10. ...></TextView>
  11. <TextView
  12. android:id="@+id/description"
  13. android:text="Description"
  14. ...></TextView>
  15. ...

Step 2. Define your content type class.

  1. data class ExampleItem (
  2. var title: String,
  3. var description: String,
  4. var img: Bitmap,
  5. ...
  6. )

Step 3. Implement your customer PagerAdapter by inheriting the abstract class LiveSliderPagerAdapter.

  1. class ExamplePageAdapter : LiveSliderPagerAdapter<ExampleItem, String>() {
  2. override fun createView(context: Context, container: ViewGroup, item: ExampleItem): View {
  3. val inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
  4. // Create and connect the view xml you want to display in the viewPager.
  5. val view = inflater.inflate(R.layout.example_page, container, false)
  6. // Put the item data into the view object you want.
  7. view.title.text = item.title
  8. view.image.setImageBitmap(item.img)
  9. ...
  10. return view
  11. }
  12. // Try adding an animation to the view object.
  13. override fun startAnimation(context: Context, view: View) {
  14. view.image.startAnimation(AnimationUtils.loadAnimation(context, R.anim.zoom))
  15. ...
  16. }
  17. override fun stopAnimation(context: Context, view: View) {
  18. view.image.clearAnimation()
  19. ...
  20. }
  21. }

Step 4. Apply the LiveSliderAdapter and your custom LiveSliderPagerAdapter on your RecycleView.

  1. mRecyclerView = findViewById(R.id.recycler_view)
  2. ...
  3. // definition of your recyclerview adapter
  4. mExampleAdapter = LiveSliderAdapter(applicationContext, ExamplePageAdapter(), true)
  5. mExampleAdapter.setHasStableIds(true)
  6. mRecyclerView.adapter = mExampleAdapter
  7. // If the ViewPager shown in RecycleView changes, start the animation.
  8. mRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
  9. override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
  10. super.onScrollStateChanged(recyclerView, newState)
  11. if(newState == RecyclerView.SCROLL_STATE_IDLE) {
  12. val layoutManager = recyclerView.layoutManager as LinearLayoutManager
  13. val animationItemPosition = layoutManager.findFirstCompletelyVisibleItemPosition()
  14. mExampleAdapter.startAnimation(animationItemPosition)
  15. }
  16. }
  17. })

Step 5. Set your recyclerview data with your contents.

When you call the setFeedData() function with parsed contents data, it applies immediately to the live-slider recyclerview.

  1. var mSampleData: Array<LiveSliderFeed<ExampleItem, String>>
  2. ...
  3. mExampleAdapter!!.setFeedData(mSampleData)

Finish!

More details are in our example project. Also, if you want to add listeners to category title like touch, you can see our other example application.

License

  1. Copyright 2019 POSCAT.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.