nestedscrollview嵌套无法流畅的滑动
lozn00 opened this issue · 3 comments
lozn00 commented
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sotrun.act.mainfun.JSONQueryTableActivity">
<LinearLayout
android:id="@+id/backdrop_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/themeColor"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/ic_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:src="@drawable/ic_menu_back"
app:tint="@color/white_no_night"
/>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginRight="@dimen/spacing_smlarge"
android:text="Filter result"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/white_no_night" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/action_cancel"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:padding="@dimen/spacing_large"
android:src="@drawable/ic_close"
android:visibility="visible"
app:tint="@color/white_no_night" />
<TextView
android:id="@+id/action_menu_export"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/export"
android:textColor="@color/white_no_night"
android:visibility="visible"
app:tint="@color/white" />
<ImageView
android:id="@+id/action_menu"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:padding="@dimen/spacing_large"
android:src="@drawable/ic_tune"
app:tint="@color/white_no_night" />
</LinearLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/layout_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
<androidx.cardview.widget.CardView
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:visibility="visible"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="6dp"
app:cardElevation="8dp">
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/refreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<androidx.core.widget.NestedScrollView
style="@style/scrollbar_style"
>
<LinearLayout
android:id="@+id/table_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- <com.sotrun.ui.thrid.MySmartTable-->
<com.bin.david.form.core.SmartTable
android:id="@+id/tableview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="100dp"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>
lozn00 commented
额,是嵌套滑动 控制fab的无法流畅的滑动
public class MySmartTable extends SmartTable implements NestedScrollingChild {
public static final String TAG = MySmartTable.class.getSimpleName();
private int mLastMotionY;
private final int[] mScrollOffset = new int[2];
private final int[] mScrollConsumed = new int[2];
private int mNestedYOffset;
private NestedScrollingChildHelper mChildHelper;
private boolean _nestedScroll=true;
public MySmartTable(Context context) {
super(context);
init(context, null, 0);
}
public MySmartTable(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public MySmartTable(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
mChildHelper = new NestedScrollingChildHelper(this);
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SmartTable, defStyle, 0);
boolean nestedScroll = a.getBoolean(R.styleable.SmartTable_nestedScrollable, _nestedScroll);
a.recycle();
mChildHelper.setNestedScrollingEnabled(nestedScroll);
} else {
mChildHelper.setNestedScrollingEnabled(true);
}
// setNestedScrollingEnabled(true);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = false;
MotionEvent trackedEvent = MotionEvent.obtain(event);
final int action = event.getActionMasked();// MotionEvent.getActionMasked(event); masked解决多指触摸bug.
if (action == MotionEvent.ACTION_DOWN) {
mNestedYOffset = 0;
}
int y = (int) event.getY();
event.offsetLocation(0, mNestedYOffset);
switch (action) {
case MotionEvent.ACTION_DOWN:
mLastMotionY = y;
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
result = super.onTouchEvent(event);
break;
case MotionEvent.ACTION_MOVE:
int deltaY = mLastMotionY - y;
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
int oldY = getScrollY();
mLastMotionY = y - mScrollOffset[1];
if (deltaY < 0) {
int newScrollY = Math.max(0, oldY + deltaY);
deltaY -= newScrollY - oldY;
if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
mLastMotionY -= mScrollOffset[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
} else {//解决 只能隐藏却无法显示问题。
int newScrollY = Math.min(0, oldY + deltaY);
deltaY -= newScrollY - oldY;
if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
mLastMotionY -= mScrollOffset[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
}
trackedEvent.recycle();
result = super.onTouchEvent(trackedEvent);
break;
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
stopNestedScroll();
result = super.onTouchEvent(event);
break;
}
return result;
}
//todo 导出待做
// NestedScrollingChild
@Override
public void setNestedScrollingEnabled(boolean enabled) {
if (mChildHelper == null) {
_nestedScroll=enabled;
return;
}
mChildHelper.setNestedScrollingEnabled(enabled);
}
@Override
public boolean isNestedScrollingEnabled() {
return mChildHelper.isNestedScrollingEnabled();
}
@Override
public boolean startNestedScroll(int axes) {
return mChildHelper.startNestedScroll(axes);
}
@Override
public void stopNestedScroll() {
if (BuildConfig.DEBUG) {
Log.w(TAG, "STOP NESTED SCROLL");
}
mChildHelper.stopNestedScroll();
}
@Override
public boolean hasNestedScrollingParent() {
return mChildHelper.hasNestedScrollingParent();
}
@Override
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
}
@Override
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
}
@Override
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
}
@Override
public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
}
}
lozn00 commented
用 协调滑动的不行。。协调滑动应该怎么改呢?
lozn00 commented
套一层nestedscrollview搞定。。