У меня есть 2 пользовательских поведения, оба они отлично работают по отдельности, но вместе они заставляют взгляды дергаться при прокрутке. Первый -
public class ViewBelowAppBarBehavior extends AppBarLayout.ScrollingViewBehavior {
private Context mContext;
private Resources r = Resources.getSystem();
private float mStartChildHeight;
private float mAppBarStartYPosition;
private int mAppBarFinalYPosition;
private float mStartAppBarPosition;
private int mMaxAppBarSize;
private float mFinalChildHeight = Math.round(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 68, r.getDisplayMetrics()));
public ViewBelowAppBarBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull View child, @NotNull View dependency) {
Log.d(TAG, "layoutDependsOn: appBar");
return dependency instanceof AppBarLayout;
}
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
InitProperties(child, dependency);
float maxAppBarScrollDistance = (-462f);
float PercentageOfAppBarScale = dependency.getY() / maxAppBarScrollDistance;
float MaxCollapseSize = mStartChildHeight - mFinalChildHeight;
if (dependency.getY() < mAppBarStartYPosition) {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
lp.height = (int) (mStartChildHeight - (MaxCollapseSize * PercentageOfAppBarScale));
child.setLayoutParams(lp);
} else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
lp.height = (int) mStartChildHeight;
child.setLayoutParams(lp);
}
return false;
}
private void InitProperties(View child, View dependency) {
if (mStartChildHeight == 0)
mStartChildHeight = child.getHeight();
if (mAppBarStartYPosition == 0)
mAppBarStartYPosition = (int) (dependency.getY());
if (mAppBarFinalYPosition == 0)
mAppBarFinalYPosition = (dependency.getHeight() / 2);
if (mStartAppBarPosition == 0)
mStartAppBarPosition = dependency.getY();
if (mMaxAppBarSize == 0)
mMaxAppBarSize = dependency.getHeight();
}
}
Второй -
public class NestedScrollBehavior extends AppBarLayout.ScrollingViewBehavior{
public NestedScrollBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return dependency.getId() == R.id.user_statistic;
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
child.setY(dependency.getBottom());
return super.onDependentViewChanged(parent, child, dependency);
}
}
Они и в макете координатора, и в nestedscroll (представление, которое применяет второе поведение) имеет привязку к Scoreboxe (представление, которое применяет первое поведение). Я думаю, что проблема в ViewBelowAppBarBehavior, вероятно, в расчетах.