我有一个带有ViewPager的MotionLayout。在ViewPager托管的一个片段中,我有一个垂直RecyclerView和两个水平RecyclerView。垂直滚动效果很好,但是,当我尝试在内部RecyclerViews上水平滚动时,效果并不理想。它似乎尝试垂直滚动(问题的视频:https://youtu.be/94rQ5Qkr2ew)我怀疑这与我使用的视图组合有关,但我不确定如何解决或确定它找出问题所在。我已经在内部(水平)RecyclerView上尝试过此方法,但似乎没有太大区别:
recyclerView.setOnTouchListener((v, event) -> {
int action = event.getAction();
View
switch (action) {
case MotionEvent.ACTION_CANCEL:
v.getParent().requestDisallowInterceptTouchEvent(false);
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
case MotionEvent.ACTION_MOVE:
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
});
这是MotionLayout容器的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout android:id="@+id/container"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutDescription="@xml/motion_scene_home_tab">
<com.github.florent37.shapeofview.shapes.DiagonalView
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="0dp"
android:elevation="@dimen/header_elevation_expanded"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shape_diagonal_angle="@dimen/menu_header_angle"
app:shape_diagonal_direction="left"
app:shape_diagonal_position="bottom">
<View
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/redE64"/>
</com.github.florent37.shapeofview.shapes.DiagonalView>
<TextView
android:id="@+id/toolbar_title"
style="@style/title.white"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/status_bar_height"
tools:text="Help Center Help Center Help Center "/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:elevation="2dp"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_title"
app:layout_constraintVertical_bias="0.0"
app:tabBackground="@color/transparent"
app:tabIndicatorColor="@color/white"
app:tabSelectedTextColor="@color/white"
app:tabTextColor="@color/white_50_percent"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
android:elevation="1dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_pager_guideline"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/view_pager_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.18"/>
</androidx.constraintlayout.motion.widget.MotionLayout>
它使用以下运动场景:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@layout/fragment_home_end"
app:constraintSetStart="@layout/fragment_home"
app:duration="500">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/view_pager"
app:touchAnchorSide="top"/>
<KeyFrameSet>
<KeyAttribute
android:elevation="0dp"
app:framePosition="0"
app:target="@id/header"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="90"
app:target="@id/header"/>
<KeyAttribute
android:elevation="@dimen/schedule_header_elevation_collapsed"
app:framePosition="100"
app:target="@id/header"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="0"
app:target="@id/toolbar"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="90"
app:target="@id/toolbar"/>
<KeyAttribute
android:elevation="@dimen/schedule_header_elevation_collapsed"
app:framePosition="100"
app:target="@id/toolbar"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="0"
app:target="@id/tabs_bar"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="90"
app:target="@id/tabs_bar"/>
<KeyAttribute
android:elevation="@dimen/schedule_header_elevation_collapsed"
app:framePosition="100"
app:target="@id/tabs_bar"/>
<KeyAttribute
android:alpha="1"
app:framePosition="0"
app:target="@id/toolbar_title"/>
<KeyAttribute
android:alpha="0"
app:framePosition="100"
app:target="@id/toolbar_title"/>
</KeyFrameSet>
</Transition>
</MotionScene>
您知道如何解决此问题吗?或至少可以改善它?
答案 0 :(得分:1)
您可以尝试此组件 https://gist.github.com/Veeyikpong/aec06cfaf66dfcad427a47654953cd7d
样品用量
只需将此组件用作XML的常规回收视图,就可以像这样:
Select COUNT(ValuableCode)
INTO L_COUNTCURS1
From TSTSHMA.CTStampCurrentEntity, TSTSHMA.CTTPValuable
Where TypeCode = PI_VALUABLECODE
and Branch = PI_Branch
and StatusX = 1
and Amount <= L_Amount
-- WHILE loop
SET L_COUNTER = 1;
WHILE L_COUNTER <= L_COUNTCURS1 DO
If ((PI_StampAmnt <= (L_AmountCUR * L_StampCurrentEntityCUR))
And (Mod(PI_StampAmnt , L_AmountCUR) = 0 )) Then
Set PO_ValuableCode = L_ValuableCodeCUR;
Set PO_StampCount = PI_StampAmnt /L_AmountCUR;
End IF;
FETCH CURSOR1 INTO L_ValuableCodeCUR ,
L_StampCurrentEntityCUR,
L_AmountCUR;
SET L_COUNTER = L_COUNTER + 1;
SET L_SQLCODE = 0;
END WHILE;
你很好! 如果可行,请标记为答案:)
答案 1 :(得分:0)
赋予 nestadscrollingenabled = false 到xml中的水平recyclerview