鼠标滚轮上的水平滚动不适用于RecyclerView Android

时间:2019-01-07 08:54:10

标签: java android xml android-recyclerview horizontal-scrolling

我已经使用了水平RecyclerView来在应用程序中进行水平滚动,但是当我尝试使用鼠标滚轮滚动时,它不会滚动而是根据光标位置单击项目。鼠标滚轮同时出现,否则不会。

activity_main.xml

<android.support.v7.widget.RecyclerView
    android:id="@+id/apps_horizontal"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_marginTop="16dp"
    android:scrollbars="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"                        
    app:layout_constraintEnd_toStartOf="@id/layout_horizontal_apps_next"
    app:layout_constraintHorizontal_weight="8"
    app:layout_constraintStart_toEndOf="@id/layout_horizontal_apps_back"
    app:layout_constraintTop_toBottomOf="parent" />

apps_horizo​​ntal_item.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="90dp"
    android:layout_height="70dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:padding="1dp"
    android:layout_marginEnd="5dp"
    android:background="@drawable/horizontal_app_background">

    <ImageView
        android:id="@+id/img_icon_apps_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_margin="20dp"
        />

</android.support.constraint.ConstraintLayout>

MainActivity.java

 adapterHorizontalApps = new HorizontalAppsAdapter(categorizedApp);
 layoutManagerHorizontalApps = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
 recyclerViewHorizontalApps = findViewById(R.id.apps_horizontal);
 recyclerViewHorizontalApps.setLayoutManager(layoutManagerHorizontalApps);
 recyclerViewHorizontalApps.setItemAnimator(new DefaultItemAnimator());
 recyclerViewHorizontalApps.setAdapter(adapterHorizontalApps);

1 个答案:

答案 0 :(得分:0)

它将永远无法工作水平滚动将随鼠标光标一起移动鼠标滚轮仅适用于垂直滚动