Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Scrollview中的RecyclerView(嵌套?),如何动态绑定项?_Android_Android Recyclerview_Scrollview_Android Nestedscrollview - Fatal编程技术网

Android Scrollview中的RecyclerView(嵌套?),如何动态绑定项?

Android Scrollview中的RecyclerView(嵌套?),如何动态绑定项?,android,android-recyclerview,scrollview,android-nestedscrollview,Android,Android Recyclerview,Scrollview,Android Nestedscrollview,我正在创建一个简单的视图,上面是一些元素,下面是一个回收视图。当我向下滚动时,想滚动整个屏幕,而不是唯一的回收者 我已经用NestedScrollView实现了这一点,但是现在问题出现了。列表中的项目将非常繁重,在此配置中,所有项目将同时绑定(调用onBindViewHolder) 有没有办法让它们循环利用并解决这个问题 这是我的xml文件 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.

我正在创建一个简单的视图,上面是一些元素,下面是一个回收视图。当我向下滚动时,想滚动整个屏幕,而不是唯一的回收者

我已经用NestedScrollView实现了这一点,但是现在问题出现了。列表中的项目将非常繁重,在此配置中,所有项目将同时绑定(调用onBindViewHolder

有没有办法让它们循环利用并解决这个问题

这是我的xml文件

   <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:orientation="vertical"
    tools:context="com.gkuziel.testkotlin.MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:src="@drawable/ic_available_stores_default" />

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test text" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list_test"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:isScrollContainer="false"
            android:nestedScrollingEnabled="false">

        </android.support.v7.widget.RecyclerView>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

您可以尝试将recyclerview布局管理器的方法canScrollVertical设置为false,并且它不会响应任何触摸内部滚动事件

重写下面的方法并返回false

boolean canScrollVertically()
这里是如何设置的

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         // ...
         // Lookup the recyclerview in activity layout
         RecyclerView listTest = (RecyclerView) findViewById(R.id.list_test);

         // Attach the adapter to the recyclerview to populate items
         listTest.setAdapter(adapter);
         // Set layout manager to position the items
         listTest.setLayoutManager(new LinearLayoutManager(this){
         @Override
         public boolean canScrollVertically(){
         return false;
       }        
     });
         // That's all!
     }

在你的Recycler视图中添加一个标题视图。可能的重复:在recyclerview的项目中添加一个大小作为图像的占位符,这样它就不会占用1px,使其在屏幕中膨胀。我认为这是不可能的,因为在主recyclerview上方也会有一个小的recyclerview..realdm-我认为情况不同,但稍后我们会看一看Marcos Vasconcelos-它已经固定了大小,问题是在其他地方
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         // ...
         // Lookup the recyclerview in activity layout
         RecyclerView listTest = (RecyclerView) findViewById(R.id.list_test);

         // Attach the adapter to the recyclerview to populate items
         listTest.setAdapter(adapter);
         // Set layout manager to position the items
         listTest.setLayoutManager(new LinearLayoutManager(this){
         @Override
         public boolean canScrollVertically(){
         return false;
       }        
     });
         // That's all!
     }