android - ScrollView 在内部 3 个 recyclerviews 中滚动不流畅

标签 android android-recyclerview scrollview

这是我的代码。我想在我的布局中放置 3 个 recyclerView,但它在设备上运行时速度非常慢。如果有 2 个 recyclerview 它运行流畅,但如果有 3 个很慢:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/scroll_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragments.MainFragment">





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



           <TextView
               android:textColor="@color/blacker"
               android:textStyle="bold"
               android:textSize="18sp"
               android:text="Техника для офиса"
               android:layout_marginTop="20dp"
               android:layout_marginLeft="15dp"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginStart="15dp" />



           <android.support.v7.widget.RecyclerView
               android:nestedScrollingEnabled="false"
               android:fillViewport="true"
               android:layout_marginBottom="15dp"
               android:layout_marginTop="15dp"
               android:id="@+id/recyclerView_popular_goods"
               android:layout_width="wrap_content"
               android:layout_height="match_parent"/>



           <TextView
               android:textColor="@color/blacker"
               android:textStyle="bold"
               android:textSize="18sp"
               android:text="Компьютерная техника"
               android:layout_marginTop="20dp"
               android:layout_marginLeft="15dp"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginStart="15dp" />



           <android.support.v7.widget.RecyclerView
               android:nestedScrollingEnabled="false"
               android:fillViewport="true"
               android:layout_marginBottom="15dp"
               android:layout_marginTop="15dp"
               android:id="@+id/recyclerView_competitive_goods"
               android:layout_width="wrap_content"
               android:layout_height="match_parent"/>



           <TextView
               android:textColor="@color/blacker"
               android:textStyle="bold"
               android:textSize="18sp"
               android:text="Канцелярские товары"
               android:layout_marginTop="20dp"
               android:layout_marginLeft="15dp"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginStart="15dp" />



           <android.support.v7.widget.RecyclerView
               android:visibility="gone"
               android:fillViewport="true"
               android:layout_marginBottom="15dp"
               android:layout_marginTop="15dp"
               android:id="@+id/recyclerView_stationery_goods"
               android:layout_width="wrap_content"
               android:layout_height="match_parent"/>

       </LinearLayout>

如果有人遇到此类问题,请帮助我解决问题。

我尝试了 Nested scrollviewsetNestedScrollingEnabled = false。但没有任何帮助

这是我的 Activity

   @SuppressLint("ValidFragment")
   public class MainFragment extends BasicFragment implements 
   MainFragmentView, PopularGoodsAdapter.ProductListener {


  @BindView(R.id.scroll_view)
  NestedScrollView mScrollView;



@BindView(R.id.recyclerView_stationery_goods)
RecyclerView mRecyclerViewStationeryGoods;


@BindView(R.id.recyclerView_popular_goods)
RecyclerView mRecyclerViewPopularGoods;


@BindView(R.id.recyclerView_competitive_goods)
RecyclerView mRecyclerViewCompetitiveGoods;


@BindView(R.id.imageSlider)
SliderView mSliderView;


@Inject
Navigator mNavigator;


@Inject
@Named(DISPLAY_WIDTH)
int mDisplayWidth;


@InjectPresenter
MainFragmentPresenter mPresenter;


List<Product> list1;
List<Product> list2;
List<Product> list3;


private PopularGoodsAdapter mAdapterPopularGoods;
private PopularGoodsAdapter mAdapterPopularGoods2;
private PopularGoodsAdapter mAdapterPopularGoods3;
private LayoutAnimationController layoutAnimationController;
private List<String> images;


@SuppressLint("ValidFragment")
public MainFragment() {

}





private void initView(View view) {
    ButterKnife.bind(this,view);

    images = new LinkedList<>();
    images.add("https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260");
    images.add("https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
    images.add("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");

    mSliderView.setSliderAdapter(new SliderAdapterExample(getContext(), images, "mainPage"));


    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    LinearLayoutManager layoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    LinearLayoutManager layoutManager3 = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);

    mRecyclerViewPopularGoods.setLayoutManager(layoutManager);

    layoutAnimationController = AnimationUtils.loadLayoutAnimation(getContext(),R.anim.layout_item_from_left);


    list1 = new LinkedList<>();
    mRecyclerViewPopularGoods.setLayoutAnimation(layoutAnimationController);



    mRecyclerViewCompetitiveGoods.setLayoutManager(layoutManager2);

    list2 = new LinkedList<>();
    mRecyclerViewCompetitiveGoods.setLayoutAnimation(layoutAnimationController);



    mRecyclerViewStationeryGoods.setLayoutManager(layoutManager3);

    list3 = new LinkedList<>();
    mRecyclerViewStationeryGoods.setLayoutAnimation(layoutAnimationController);



    mRecyclerViewPopularGoods.setAdapter(mAdapterPopularGoods = new PopularGoodsAdapter(getContext(),list1,mDisplayWidth,"popular",this));
    mRecyclerViewCompetitiveGoods.setAdapter(mAdapterPopularGoods2 = new PopularGoodsAdapter(getContext(),list2,mDisplayWidth,"competitive",this));
    mRecyclerViewStationeryGoods.setAdapter(mAdapterPopularGoods3 = new PopularGoodsAdapter(getContext(),list3,mDisplayWidth,"stationery",this));

    mRecyclerViewPopularGoods.setNestedScrollingEnabled(false);
    mRecyclerViewCompetitiveGoods.setNestedScrollingEnabled(false);
    mRecyclerViewStationeryGoods.setNestedScrollingEnabled(false);


    getLoadingDialog().showDialog(getFragmentManager());
    mPresenter.GET_TOP_HOME_VIEW();

}




@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup 
   container, 
  Bundle savedInstanceState) {

      View view =  inflater.inflate(R.layout.fragment_main, container, 
     false);
    initView(view);
    return view;
  }










@OnClick({R.id.item_sellers,
 R.id.item_price_request,R.id.item_price_competitions})
  void Onclick(View view) {
      switch (view.getId()) {

        case R.id.item_sellers:

                mNavigator.toSellersActivty(getContext());

            break;

        case R.id.item_price_request:

                mNavigator.toPriceRequestActivty(getContext());

            break;

        case R.id.item_price_competitions:

                mNavigator.toCompetitionsActivty(getContext());

            break;

    }
}




@Override
public void initTopHomeView(List<HomeViewObject> result) {

    if (null != result ) {

        if (result.size() >= 1 && null != result.get(0)) {
            list1.addAll(result.get(0).getTopProducts());
            mAdapterPopularGoods.notifyDataSetChanged();
            mRecyclerViewPopularGoods.setLayoutAnimation(layoutAnimationController);

        }

        if (result.size() >= 2 && null != result.get(1)) {
            list2.addAll(result.get(1).getTopProducts());
            mAdapterPopularGoods2.notifyDataSetChanged();
            mRecyclerViewPopularGoods.setLayoutAnimation(layoutAnimationController);
        }

        if (result.size() >= 3 && null != result.get(2)) {
            list3.addAll(result.get(2).getTopProducts());
            mAdapterPopularGoods3.notifyDataSetChanged();
            mRecyclerViewStationeryGoods.setLayoutAnimation(layoutAnimationController);
        }

    }




}



@Override
public void stopProgress() {
    getLoadingDialog().hideDialog();
}



@Override
public void onProductClicked(Product product) {
    mNavigator.toProductActivity(getContext(),product);
 }
  }

有没有错误?

最佳答案

尝试以下 -

  1. 尝试将所有 View 放在 NestedScrollView 中,即 Root View 。

  2. 设置 recyclerView.setNestedScrollingEnabled(false);对于您的 xml 中的两个 recyclerView。

关于android - ScrollView 在内部 3 个 recyclerviews 中滚动不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58870771/

相关文章:

java - 算法 HmacPBESHA256 不可用(Flutter 构建失败)

android - 如何使用字符串值从适配器中的Mysql设置imageview

android - 具有多个项目选取框的回收站 View

ios - 单击 tableView 中的文本字段时,ScrollView 没有向上移动

android.os.FileUriExposedException : file:///storage/emulated/0/test. txt 通过 Intent.getData() 暴露在应用之外

android - 将 Eclipse 连接到不同机器上的 Android 模拟器

android - 如何通过特定像素以编程方式滚动 RecyclerView?

android - 如何创建不在 ScrollView 中或 ScrollView 已禁用的 ListView?

android - Xamarin:Scrollview 中的 PanGestureRecognizer (Android)

android - 我们可以在短信中传递 Uri 而不是 Android 中的超链接吗