我的应用程序中有一个嵌套的滚动视图。 问题是滚动很慢。
该问题仅发生在安卓 6 中。
我班上有这个:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<RelativeLayout
android:id="@+id/pro"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="?attr/colorPrimary"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/imageViewP"
android:layout_width="30dp"
android:layout_height="30dp"
android:cropToPadding="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/p2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#fff"
android:layout_below="@+id/pro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:text="Sells"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView4"
android:textStyle="normal|bold"
android:layout_marginRight="66dp"
android:layout_marginEnd="66dp"
android:layout_alignParentTop="true"
android:textSize="12dp"
android:layout_marginTop="5dp" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/idFollowers"
android:gravity="center"
android:layout_below="@+id/textView4"
android:layout_alignLeft="@+id/textView4"
android:layout_alignStart="@+id/textView4"
android:layout_alignRight="@+id/textView4"
android:textSize="12dp"
android:layout_alignEnd="@+id/textView4" />
</RelativeLayout>
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_below="@+id/p2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
任何想法如何获得流畅的滚动? 为什么我的安卓 6 很慢?
为什么要在
嵌套的ScrollView中嵌套RecyclerView,RecyclerView已经处理了自己的滚动,可能他们都在努力获得焦点。将这些添加到回收器视图
android:focusable="false"
android:focusableInTouchMode="true"
将此添加到嵌套滚动视图
android:descendantFocusability="blocksDescendants"
同样如前所述,swipeRefreshLay也可能是罪魁祸首。