都是在网上找的会附赠网址,侵权即删
第一个是先解决ScrollView+ViewPager不显示问题 网上的其他解决方案俺就不解释了 不好用就是不好用
这个解决方案是重新测量高度 去自适应 嵌套进普通ScrollView即可
转载地址https://blog.youkuaiyun.com/g401946949/article/details/53187319
<com.guanyueyun.mylook.view.CustomViewPager
android:id="@+id/view_home_main_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" />
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height)height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
然后解决viewpager里的fragment里的RecyclerView
我写的商品详细,所以我不需要点击事件,但是他滑动到这里一定会卡,没有滑动感,所以我屏蔽了RecyclerView的滑动
若有其他解决办法也可留言,我只是针对我自己的项目写出对应解决办法
转载https://blog.youkuaiyun.com/lengqi0101/article/details/52874762
public class CustomLinearLayoutManager extends LinearLayoutManager {
private boolean isScrollEnabled = true;
public CustomLinearLayoutManager(Context context) {
super(context);
}
public void setScrollEnabled(boolean flag) {
this.isScrollEnabled = flag;
}
@Override
public boolean canScrollVertically() {
//Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
return isScrollEnabled && super.canScrollVertically();
}
}
CustomLinearLayoutManager linearLayoutManager = new CustomLinearLayoutManager(mContext);
linearLayoutManager.setScrollEnabled(false);
mDevicesRV.setLayoutManager(linearLayoutManager);
亲测可用
然后下一章单说这个问题。
本文提供了一种解决ScrollView与ViewPager结合使用时显示问题的方法,并介绍了一种自定义的LinearLayoutManager来解决ViewPager中Fragment内RecyclerView滑动卡顿的问题。
1998

被折叠的 条评论
为什么被折叠?



