【发布时间】:2018-12-12 08:56:35
【问题描述】:
在深入研究代码之前,我已经检查了以下问题:
- How to use RecyclerView inside NestedScrollView?
- Recyclerview inside Nested Scrollview scroll but does not fast scroll like normal Recyclerview or Nested Scrollview
- RecyclerView inside a ScrollView/NestedScrollView does not scroll properly
上述问题都没有对我有用。 RecyclerView 滚动时太迟钝。
我有一个NestedScrollview 和一个LinearLayout 作为NestedScrollview 的主要布局。布局的代码是:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:fbutton="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/frag_misc_rv_margin_top"
android:scrollbars="none"
android:nestedScrollingEnabled="false"
android:id="@+id/frag_showcase_promotion_recyclerview"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
代码是:
mPromotionsRv.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false));
mPromotionsRv.setNestedScrollingEnabled(false);
mPromotionsAdapter = new ShowcasePromotionRvAdapter(getActivity(), mPromotionsItems);
mPromotionsAdapter.setOnItemClickListener(new ShowcasePromotionListener() {
@Override
public void onClick(View view, int position) {
ItemPromotion mPromotion = mPromotionsItems.get(position);
try{
recordPromotionClick(mPromotion.getId());
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(mPromotion.getPromotion_link())));
} catch (Exception e){
e.printStackTrace();
}
}
});
mPromotionsRv.setAdapter(mPromotionsAdapter);
SnapHelper snapHelperStart = new GravitySnapHelper(Gravity.START);
snapHelperStart.attachToRecyclerView(mPromotionsRv);
RecyclerView.ItemAnimator animator = mPromotionsRv.getItemAnimator();
if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }
【问题讨论】:
-
基本上无论如何,使用
wrap_content和RecyclerView总是会冒使用太多资源的风险。 -
我试过设置高度,但一点帮助都没有。
标签: android android-recyclerview android-nestedscrollview