Skip to content

Commit

Permalink
merge 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
luiing committed May 23, 2019
2 parents 0ab393d + d751108 commit 2dc9408
Show file tree
Hide file tree
Showing 55 changed files with 314 additions and 858 deletions.
89 changes: 74 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,87 @@

### 吸顶解决方案(demo模块)
1. Single RecyclerView:简单模式【利用RecyclerView.OnScrollListener监听滑动位置,吸顶View被 ViewHolder和Activity复用】
### 吸顶解决方案(终极版)

1. Single RecyclerView:简单模式
【利用RecyclerView.OnScrollListener监听滑动位置,吸顶View被 ViewHolder和Activity复用】

2. Double RecyclerView:RecyclerView嵌套RecyclerView
【事件分发,吸顶View是个单独ViewHolder,无须做其他处理】

2. Double RecyclerView:RecyclerView嵌套RecyclerView【事件分发,吸顶View是个单独ViewHolder,无须做其他处理】
3. Viewpager RecyclerView:RecyclerView嵌套ViewPager(其中包含的页面内容是RecyclerView)
【事件分发,吸顶View是个单独ViewHolder,无须做其他处理】

3. Viewpager RecyclerView:RecyclerView嵌套ViewPager(其中包含的页面内容是RecyclerView)【事件分发,吸顶View是个单独ViewHolder,无须做其他处理】
4. 项目无偿使用,请注明出处和作者信息


### PREVIEW
![](/preview/001.png)
### USE
##### Single
recyclerView.addOnScrollListener(object : SingleAdsorbentListener(){
/** 获取被吸顶ViewGroup*/
override fun getUiViewGroup(): ViewGroup = relative
/** 获取吸顶View*/
override fun getPinView(): View = pin
/** 获取吸顶View在RecyclerView中的位置*/
override fun getPinViewPosition(): Int = 15
})
##### Double
//recyclerView is ParentRecyclerView
manager = LinearLayoutManager(this)
recyclerView.layoutManager = manager
recyclerView.adapter = adapter

//itemView.recyclerview is ChildRecyclerView as ViewHolder
init {
val p = itemView.recyclerview.layoutParams
/** 吸顶高+child recyclerView高 = recyclerView高*/
val height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50f, parent.resources.displayMetrics) + 0.5f
p.height = parent.measuredHeight - height.toInt()
itemView.recyclerview.layoutParams = p

val adapter = DemoGroupAdapter()
for(i in 0 until 50) {
adapter.addEntity(GroupEntity(VT_TXT, "Child RecyclerView item $i"))
}
val recycler = itemView.recyclerview
recycler.layoutManager = LinearLayoutManager(parent.context)
recycler.adapter = adapter
}

##### Viewpager
//recyclerView is ParentRecyclerView
manager = LinearLayoutManager(this)
recyclerView.layoutManager = manager
recyclerView.adapter = adapter

//ViewPager as ViewHolder,ChildRecycler is ViewPager Item
override fun instantiateItem(container: ViewGroup, position: Int): Any {
var view :RecyclerView? = null
while(views.size > 0 && view == null){
view = views.removeLast()
}
if(view == null){
view = ChildRecyclerView(container.context)
view.layoutManager = LinearLayoutManager(container.context)
}
if(view.adapter == null){
val adapter = DemoGroupAdapter()
for(i in 0 until 50) {
adapter.addEntity(GroupEntity(VT_TXT, "ViewPager嵌套RecyclerView item $i"))
}
view.adapter = adapter
}
container.addView(view)
return view
}


### USE by Kotlin
implementation 'com.uis:groupadapter:0.4.0
implementation 'com.uis:adsorbent:0.1.1
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:recyclerview-v7:$supportVer"

maven {url 'https://dl.bintray.com/sweet/maven'}

``` 项目中使用的是compileOnly,使用者需自行加入外部依赖库 ```

```
```



``` 项目中使用的是compileOnly,使用者需自行加入外部依赖库,请加上私有仓储 ```

### VERSION

Expand Down
15 changes: 6 additions & 9 deletions adsorbent/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion compileVer
buildToolsVersion buildToolsVer
defaultConfig {
applicationId "com.uis.groupadater.demo"
minSdkVersion minSdkVer
targetSdkVersion targetVer
versionCode 1
versionName "1.0"
//ndk{
//abiFilters 'x86'//'armeabi-v7a'
//}
}

buildTypes {
Expand All @@ -27,8 +23,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:'+supportVer
implementation 'com.android.support:appcompat-v7:'+supportVer
implementation 'com.android.support:recyclerview-v7:'+supportVer
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly 'com.android.support:recyclerview-v7:'+supportVer
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}


//apply from: '../../../bintray.gradle'
23 changes: 7 additions & 16 deletions adsorbent/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
<!--
~ Copyright (c) 2019 by uis
~ Author: uis
~ Github: https://github.com/luiing
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.uis.groupadater.demo">
<application
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".DemoUi">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".SingleRecyclerUi"/>
<activity android:name=".DoubleRecyclerUi"/>
<activity android:name=".ViewpagerRecyclerUi"/>
</application>
package="com.uis.adsorbent">
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.uis.groupadater.demo.adsorbent
/*
* Copyright (c) 2019 by uis
* Author: uis
* Github: https://github.com/luiing
*/

package com.uis.adsorbent

import android.content.Context
import android.support.v7.widget.RecyclerView
Expand All @@ -10,16 +16,20 @@ class ChildRecyclerView :RecyclerView{
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

var enableConflict = true

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
/** true child在顶部*/
val isChildTop = !canScrollVertically(-1)
var pv = parent
while (pv != null) {
if (pv is OnInterceptListener) {
pv.onTopChild(isChildTop)
break
if(enableConflict) {
val isChildTop = !canScrollVertically(-1)
var pv = parent
while (pv != null) {
if (pv is OnInterceptListener) {
pv.onTopChild(isChildTop)
break
}
pv = pv.parent
}
pv = pv.parent
}
return super.dispatchTouchEvent(ev)
}
Expand Down
11 changes: 11 additions & 0 deletions adsorbent/src/main/java/com/uis/adsorbent/OnInterceptListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2019 by uis
* Author: uis
* Github: https://github.com/luiing
*/

package com.uis.adsorbent

interface OnInterceptListener {
fun onTopChild(isTop :Boolean)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.uis.groupadater.demo.adsorbent
/*
* Copyright (c) 2019 by uis
* Author: uis
* Github: https://github.com/luiing
*/

package com.uis.adsorbent

import android.content.Context
import android.os.SystemClock
Expand All @@ -7,7 +13,7 @@ import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.MotionEvent

class ParentRecyclerView :RecyclerView,OnInterceptListener{
class ParentRecyclerView :RecyclerView, OnInterceptListener {

constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
Expand All @@ -33,11 +39,10 @@ class ParentRecyclerView :RecyclerView,OnInterceptListener{
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
return dispatchConflictTouchEvent(ev) || super.dispatchTouchEvent(ev)
return (enableConflict && dispatchConflictTouchEvent(ev)) || super.dispatchTouchEvent(ev)
}

private fun dispatchConflictTouchEvent(ev: MotionEvent):Boolean{
if(!enableConflict) return false
when(ev.action){
MotionEvent.ACTION_DOWN ->{
startdx = ev.x
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.uis.groupadater.demo.adsorbent
/*
* Copyright (c) 2019 by uis
* Author: uis
* Github: https://github.com/luiing
*/

package com.uis.adsorbent

import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2dc9408

Please sign in to comment.