Skip to content

Commit

Permalink
版本0.9.10,改为kotlin,支持相对布局
Browse files Browse the repository at this point in the history
  • Loading branch information
weimingjue committed Jul 16, 2021
1 parent 06cbe24 commit 8fb3f82
Show file tree
Hide file tree
Showing 13 changed files with 496 additions and 517 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# 主要解决AppBarLayout的置顶效果存在的以下问题

1.头部超过一屏回拉会出现明显卡顿

2.惯性滑动无法用手指停下
Expand Down Expand Up @@ -91,11 +90,13 @@ allprojects {
}
```
然后:
`implementation(或api) 'com.github.weimingjue:sticky:0.9.8'`
`implementation(或api) 'com.github.weimingjue:sticky:0.9.9'`

## 说明
如果没有tag="sticky"则它就是一个可嵌套滑动的view

支持androidX所有view及第三方的View嵌套,不支持ListView

Android5.0及以后可以使用RelativeLayout和ConstantLayout

无需混淆配置
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion COMPILE_SDK_VERSION
Expand All @@ -25,10 +26,12 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':sticky')
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'

//自己的adapter
api 'com.github.weimingjue:BaseAdapter:4.1.3'
api 'com.github.weimingjue:BaseAdapter:4.3.0'
implementation "androidx.core:core-ktx:1.3.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="com.wang.example">

<application
android:name=".MyApplication"
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/wang/example/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wang.example

import android.app.Application
import android.widget.Toast
import com.wang.example.App.Companion.app

class App : Application() {
companion object {
lateinit var app: App
}

override fun onCreate() {
super.onCreate()
app = this;
}
}

fun getApp(): Application {
return app
}

fun CharSequence.toast() {
Toast.makeText(getApp(), this, Toast.LENGTH_SHORT).show()
}
37 changes: 0 additions & 37 deletions app/src/main/java/com/wang/example/MainActivity.java

This file was deleted.

29 changes: 29 additions & 0 deletions app/src/main/java/com/wang/example/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.wang.example

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.wang.adapters.adapter.BaseAdapterRvList
import com.wang.sticky.StickyNestedScrollLayout
import java.util.*

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rv = findViewById<RecyclerView>(R.id.rv_main)
val adapter = BaseAdapterRvList.createAdapter<String>(R.layout.adapter_main)
val list = ArrayList<String>()
for (i in 0..79) {
list.add("$i")
}
adapter.setListAndNotifyDataSetChanged(list)
rv.adapter = adapter

val snsl = findViewById<StickyNestedScrollLayout>(R.id.snsl_main)
//代码设置
// val tv = findViewById<TextView>(R.id.tv_main)
// snsl.setChildTag(tv, StickyNestedScrollLayout.TAG_STICKY)
// snsl.setChildTag(rv, StickyNestedScrollLayout.TAG_MATCH)
}
}
17 changes: 0 additions & 17 deletions app/src/main/java/com/wang/example/MyApplication.java

This file was deleted.

45 changes: 26 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,48 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2"
android:textSize="80sp" />

<TextView
android:layout_width="wrap_content"
android:focusableInTouchMode="true"
android:focusable="true"
android:layout_height="wrap_content"
android:text="3\n4"
android:textSize="80sp" />
android:textSize="80sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:tag="sticky"
android:text="悬浮1"
android:textSize="30sp" />
android:textSize="30sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv1" />

<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5\n6"
android:textSize="80sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7\n8\n9"
android:textSize="80sp" />
android:textSize="80sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv2" />

<FrameLayout
android:id="@+id/tv5"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv3">

<TextView
android:layout_width="wrap_content"
Expand All @@ -64,18 +66,23 @@
</FrameLayout>

<TextView
android:id="@+id/tv6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="哈哈"
android:textSize="80sp" />
android:textSize="80sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv5" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="match"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv6"
app:spanCount="2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.wang.sticky.StickyNestedScrollLayout>
</LinearLayout>
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.32'
repositories {
maven { url 'https://jitpack.io' }
google()
jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -27,11 +29,11 @@ task clean(type: Delete) {
}
ext {
//用于编译的SDK版本
COMPILE_SDK_VERSION = 28
COMPILE_SDK_VERSION = 29

//最低支持Android版本
MIN_SDK_VERSION = 16

//目标版本
TARGET_SDK_VERSION = 28
TARGET_SDK_VERSION = 29
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Dec 26 13:10:11 CST 2020
#Tue Apr 27 15:19:57 CST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
5 changes: 3 additions & 2 deletions sticky/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion COMPILE_SDK_VERSION
Expand All @@ -24,6 +25,6 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.core:core-ktx:1.3.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Loading

0 comments on commit 8fb3f82

Please sign in to comment.