Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_goodmoney
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_goodmoney
Commits
8df2e49c
Commit
8df2e49c
authored
Nov 25, 2020
by
jyx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
3164499e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
FlingBehavior.java
...in/java/com/mints/goodmoney/ui/widgets/FlingBehavior.java
+16
-4
No files found.
GoodMoney/app/src/main/java/com/mints/goodmoney/ui/widgets/FlingBehavior.java
View file @
8df2e49c
...
@@ -6,6 +6,8 @@ import android.view.MotionEvent;
...
@@ -6,6 +6,8 @@ import android.view.MotionEvent;
import
android.view.View
;
import
android.view.View
;
import
android.widget.OverScroller
;
import
android.widget.OverScroller
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.coordinatorlayout.widget.CoordinatorLayout
;
import
androidx.coordinatorlayout.widget.CoordinatorLayout
;
import
com.google.android.material.appbar.AppBarLayout
;
import
com.google.android.material.appbar.AppBarLayout
;
...
@@ -14,7 +16,7 @@ import com.mints.goodmoney.utils.LogUtil;
...
@@ -14,7 +16,7 @@ import com.mints.goodmoney.utils.LogUtil;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
/**
/**
*
解决appbarLayout若干问题:
* 解决appbarLayout若干问题:
* (1)快速滑动appbarLayout会出现回弹
* (1)快速滑动appbarLayout会出现回弹
* (2)快速滑动appbarLayout到折叠状态下,立马下滑,会出现抖动的问题
* (2)快速滑动appbarLayout到折叠状态下,立马下滑,会出现抖动的问题
* (3)滑动appbarLayout,无法通过手指按下让其停止滑动
* (3)滑动appbarLayout,无法通过手指按下让其停止滑动
...
@@ -33,6 +35,14 @@ public class FlingBehavior extends AppBarLayout.Behavior {
...
@@ -33,6 +35,14 @@ public class FlingBehavior extends AppBarLayout.Behavior {
public
FlingBehavior
(
Context
context
,
AttributeSet
attrs
)
{
public
FlingBehavior
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
super
(
context
,
attrs
);
// 处理appbarlayout 无法滑动问题
setDragCallback
(
new
DragCallback
()
{
@Override
public
boolean
canDrag
(
@NonNull
AppBarLayout
appBarLayout
)
{
return
true
;
}
});
}
}
@Override
@Override
...
@@ -54,6 +64,7 @@ public class FlingBehavior extends AppBarLayout.Behavior {
...
@@ -54,6 +64,7 @@ public class FlingBehavior extends AppBarLayout.Behavior {
/**
/**
* 反射获取私有的flingRunnable 属性,考虑support 28以后变量名修改的问题
* 反射获取私有的flingRunnable 属性,考虑support 28以后变量名修改的问题
*
* @return Field
* @return Field
*/
*/
private
Field
getFlingRunnableField
()
throws
NoSuchFieldException
{
private
Field
getFlingRunnableField
()
throws
NoSuchFieldException
{
...
@@ -70,6 +81,7 @@ public class FlingBehavior extends AppBarLayout.Behavior {
...
@@ -70,6 +81,7 @@ public class FlingBehavior extends AppBarLayout.Behavior {
/**
/**
* 反射获取私有的scroller 属性,考虑support 28以后变量名修改的问题
* 反射获取私有的scroller 属性,考虑support 28以后变量名修改的问题
*
* @return Field
* @return Field
*/
*/
private
Field
getScrollerField
()
throws
NoSuchFieldException
{
private
Field
getScrollerField
()
throws
NoSuchFieldException
{
...
@@ -86,9 +98,11 @@ public class FlingBehavior extends AppBarLayout.Behavior {
...
@@ -86,9 +98,11 @@ public class FlingBehavior extends AppBarLayout.Behavior {
/**
/**
* 停止appbarLayout的fling事件
* 停止appbarLayout的fling事件
*
* @param appBarLayout
* @param appBarLayout
*/
*/
private
void
stopAppbarLayoutFling
(
AppBarLayout
appBarLayout
)
{
private
void
stopAppbarLayoutFling
(
AppBarLayout
appBarLayout
)
{
LogUtil
.
d
(
TAG
,
"stopAppbarLayoutFling"
);
//通过反射拿到HeaderBehavior中的flingRunnable变量
//通过反射拿到HeaderBehavior中的flingRunnable变量
try
{
try
{
Field
flingRunnableField
=
getFlingRunnableField
();
Field
flingRunnableField
=
getFlingRunnableField
();
...
@@ -106,9 +120,7 @@ public class FlingBehavior extends AppBarLayout.Behavior {
...
@@ -106,9 +120,7 @@ public class FlingBehavior extends AppBarLayout.Behavior {
if
(
overScroller
!=
null
&&
!
overScroller
.
isFinished
())
{
if
(
overScroller
!=
null
&&
!
overScroller
.
isFinished
())
{
overScroller
.
abortAnimation
();
overScroller
.
abortAnimation
();
}
}
}
catch
(
NoSuchFieldException
e
)
{
}
catch
(
NoSuchFieldException
|
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment