【问题标题】:Listview inside RecyclerView scroll not working properly?RecyclerView 滚动中的 Listview 无法正常工作?
【发布时间】:2018-05-14 12:45:19
【问题描述】:

我正在研究将 ListView 作为列表项的 RecyclerView。 我正在为 RecyclerView 使用 LinearLayoutManager。 ListView 有大量水平和垂直滚动的数据。 但在我的情况下,在纵向模式下它会停止垂直滚动,而在横向模式下,它会停止水平滚动。要求是不可能改变的。有什么建议可以解决这个问题。我附上了我的部分代码。

列表项:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/info_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:elevation="5dp"
android:orientation="vertical"
android:visibility="visible">

<View
    android:id="@+id/line"
    android:layout_width="match_parent"
    android:layout_height="2px"
    android:background="@color/table_item_even" />

<ListView
    android:id="@+id/lst_info"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:divider="@null"
    android:dividerHeight="0dp"
    android:scrollbars="horizontal|vertical"
    android:transcriptMode="alwaysScroll"></ListView>

回收站视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_multiprobs_info"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>

LinearLayoutManager 方向改变模式:

 if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        } else {
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        }

【问题讨论】:

  • 我认为 getResources().getConfiguration().orientation 可能会返回“错误”的方向。你什么时候打电话?
  • 也许尝试使用“Display getOrient = activity.getWindowManager().getDefaultDisplay();”来获取显示。然后用显示的高度和宽度构建你的 if。
  • @GAlexMES 我想你不明白这个问题。如果定向条件正常。
  • 你可以考虑看看这个answer
  • @ReazMurshed 它帮助了我

标签: android android-recyclerview


【解决方案1】:

我忘了做下面的技术。一个非常简单的覆盖方法保存了我的程序。我只关注 RecyclerView 而不是 LayoutManager 这是一个错误。

 layoutManager = new LinearLayoutManager(context){
        @Override
        public boolean canScrollVertically() {
            return false;
        }

        @Override
        public boolean canScrollHorizontally() {
            return false; 
        }
    };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    相关资源
    最近更新 更多