这是我的代码。我想在我的布局中放置3个recyclerViews,但是在运行时设备上的速度非常慢。如果有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。但是没有帮助

这是我的活动

   @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);
 }
  }


有什么错误吗?

最佳答案

试试以下-


尝试将所有视图放入NestedScrollView内,即根视图。
设置recyclerView.setNestedScrollingEnabled(false); xml中的两个recyclerViews。

10-08 14:52