gpt4 book ai didi

android - Viewpager 滑动不适用于回收站 View

转载 作者:行者123 更新时间:2023-11-29 02:24:46 26 4
gpt4 key购买 nike

我在同一个 Activity 中有一个 ViewPager 和 RecyclerView,并且这两个 View 重叠(RecyclerView 在前面,ViewPager 在后面)。当我在空白处滑动时,我的 ViewPager 滑动工作正常,但是当我在 RecyclerView 上滑动时,viewpager 滑动不起作用。我在 Recyclerview 中有按钮和搜索栏。当用户在 RecyclerView 上滑动时,我想滑动 ViewPager,seekbar 除外。

我的布局是:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />

<RelativeLayout
android:id="@+id/imagesLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/bottomRelativeLayout"
android:layout_below="@+id/timerLayout"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:visibility="gone">


<android.support.v7.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:clickable="true"
android:fadingEdgeLength="30dp"
android:focusable="true"
android:gravity="center"
android:horizontalSpacing="3dp"
android:listSelector="@android:color/transparent"
android:numColumns="3"
android:overScrollMode="never"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:requiresFadingEdge="vertical"
android:scrollbars="none" />


</RelativeLayout>

我的java代码是:

 imagesRecyclerView = (RecyclerView) findViewById(R.id.myRecyclerView);
int numberOfColumns = 3;
imagesRecyclerView.setLayoutManager(new GridLayoutManager(context, numberOfColumns));
imagesRecyclerView.getItemAnimator().setChangeDuration(0);
imagesRecyclerView.setHasFixedSize(false);

我搜索了很多关于这个主题但我找不到任何解决方案。我的 viewpager 适配器看起来像:

public class ViewPagerAdapter extends FragmentStatePagerAdapter {
FragmentManager fm;
private SparseArray<Fragment> registeredFragments = new SparseArray<>();

public ViewPagerAdapter(FragmentManager fm) {
super(fm);
this.fm=fm;


}


@Override
public Fragment getItem(int position) {

Fragment fragment = new ImageFragment();

Bundle args = new Bundle();

args.putSerializable("TabObject", Constants.tabs.get(position));

fragment.setArguments(args);


return fragment;
}

@Override
public int getCount() {
return Constants.tabs.size();
}

@SuppressLint("RestrictedApi")
public List<Fragment> getFragments(){
return fm.getFragments();
}

@Override
public int getItemPosition(Object object) {
if (object instanceof ImageFragment) {
// Create a new method notifyUpdate() in your fragment
// it will get call when you invoke
// notifyDatasetChaged();
// ((SoundsFragment) object).updateGridData();
}
//don't return POSITION_NONE, avoid fragment recreation.
return super.getItemPosition(object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
registeredFragments.put(position, fragment);
return fragment;
}

public Fragment getRegisteredFragment(int position) {
return registeredFragments.get(position);
}

@Override
public CharSequence getPageTitle(int position) {
return "OBJECT " + (position + 1);
}

}

最佳答案

你可以使用

1)

ViewCompat.setNestedScrollingEnabled(recyclerView, false);

2)在你的recylerView标签内

app:layout_behavior="@string/appbar_scrolling_view_behavior"

关于android - Viewpager 滑动不适用于回收站 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52936591/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com