我的应用程序的设计
屏幕 - 1
<NestedScrollview>
<LinearLayout orientation:horizontal">
<RecyclerView-1>
<Framelayout>(contains Recyclerview-2)
</NestedScroll>
Run Code Online (Sandbox Code Playgroud)
屏幕 - 2
<NestedScrollview>
<LinearLayout orientation:horizontal">
<RecyclerView-1>
<Framelayout> (fragment changed, contains Recyclerview-3)
</NestedScroll>
Run Code Online (Sandbox Code Playgroud)
现在,如果用户在屏幕 1 上,则两个 recyclerview 将同时滚动,但在屏幕 2 上,如果用户滚动 RV1,则只有 RV1 会类似地滚动,如果 RV3 滚动,则 RV3 将滚动。尝试了各种停止滚动,但无法停止嵌套滚动视图的滚动。
android android-recyclerview android-framelayout android-nestedscrollview
我在nestedscrollview中有recyclerview:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<org.apmem.tools.layouts.FlowLayout
android:id="@+id/filter_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_main"
android:paddingLeft="@dimen/small_horizontal_margin"
android:paddingRight="@dimen/small_horizontal_margin"
/>
<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical"
android:paddingTop="@dimen/vertical_margin"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
Recyclerview有OnScrollListener正在处理从这个例子采取无休止的滚动:https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView.但是看起来nestedscrollview正在触发onScrolled方法,所以整个项目列表都会立即加载.
问题: 如何防止这种行为?
请注意,一切都适用于recyclerview,而不是在nestedscrollview中
android endlessscroll android-recyclerview android-nestedscrollview
运行Android Studio 2.1.2,Windows 7.
我用NestedScrollView替换了ScrollView,现在我得到了
android.view.InflateException:二进制XML文件行#2:错误膨胀类NestedScrollView
java.lang.ClassNotFoundException:在路径上找不到类"android.view.NestedScrollView":/ data/app/com.assemblyguide.remote-48.apk
...当我在该XML文件上调用SetContentView()时.当我只有一个ScrollView时,我没有得到它.
我已经尝试过清理,并使缓存无效并重建.XML看起来像这样...
<?xml version="1.0" encoding="utf-8"?>
<NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- This linear layout is because the scrollview can have only 1 direct child -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Relative layout for Workorder -->
<RelativeLayout
android:id="@+id/rellayWorkorder"
android:background="#383838"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="2dp">
<TextView
android:id="@+id/workorderlabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="2dp"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Work Order:"/>
<TextView
android:id="@+id/workorderContent"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="2dp"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="---workorder---"/>
</RelativeLayout>
<!-- Relative layout for Required Time
<FrameLayout …Run Code Online (Sandbox Code Playgroud) 我有一个建筑,其中有两个项目是静态和recyclerview与可拖动的项目.两种类型的视图都由LinearLayout包装.LinearLayout由NestedScrollView包装.
XML说明:
<NestScrollView>
<LinearLayout>
<View></View>
<View></View>
<RecyclerView></RecyclerView>
</LinearLayout>
</NestScrollView>
Run Code Online (Sandbox Code Playgroud)
图解说明:
我从本教程中拖拽项目的实现:https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-6a6f0c422efd#.yc7me2ikf
问题是RecyclerView当我将他的孩子拖出屏幕时不会滚动.(但是,如果我没有NestedScrollView作为父母,RecyclerView按预期工作.)
我搜索了与此相关的每个问题,但我没有找到任何解决方案.
我有一个NestedScrollView填充了一个垂直的LinearLayout,它本身有一堆各种视图类型的子项:多个TextViews,两个静态GridViews,甚至一个FrameLayout来显示所有这些下面的片段.
当按下后退按钮时,如果用户滚动到某个点以下,而不是完成活动,则调用"scrollToTop"方法:
public static void scrollToTop(final NestedScrollView scrollview) {
new Handler().postDelayed(new Runnable() {
public void run() {
scrollview.fullScroll(NestedScrollView.FOCUS_UP);
}
}, 200);
}
Run Code Online (Sandbox Code Playgroud)
这适用于我的应用程序的早期版本,该版本位于Play商店中.但现在,在更新我的应用程序以定位Android Oreo(并将支持库更新到版本26.0.2)之后,它似乎从NestedScrollView的原始滚动位置下方开始滚动,而不是滚动到顶部,并停止它的位置.所以它只是看起来像一个奇怪的口吃.然而,在某些位置,它确实滚动到顶部(尽管非常罕见且不一致),而其他位置实际上滚动到底部,出于什么原因我不明白.
我一直在试验视图的可聚焦性,但无济于事.例如,我读到静态GridViews可能会在滚动时中断焦点.我也尝试了各种不同的方法来向上滚动,例如
scrollview.pageScroll(View.FOCUS_UP);
Run Code Online (Sandbox Code Playgroud)
和
scrollview.smoothScrollTo(0,0);
Run Code Online (Sandbox Code Playgroud)
但似乎没有任何效果.这次支持库有什么问题吗?
我想实现分页recyclerView,为此我添加addOnScrollListener了recyclerView但是我在RecyclerView.OnScrollListener设置时没有工作的麻烦rvGridExplore.setNestedScrollingEnabled(false);
但当我删除rvGridExplore.setNestedScrollingEnabled(false);它工作正常,我不知道如何处理这个.
这是代码:
rvGridExplore = (RecyclerView) view.findViewById(R.id.rvGridExplore);
final GridLayoutManager glm = new GridLayoutManager(context,2);
// rvGridExplore.setNestedScrollingEnabled(false);
rvGridExplore.setLayoutManager(glm);
// final int visibleItemCount,totalCount,pastVisibleItems;
rvGridExplore.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
Log.v("scrollll","state changed");
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
int totalCount = glm.getItemCount();
int visibleItemCount = glm.getChildCount();
int pastVisibleItems = glm.findFirstVisibleItemPosition();
if (loading) { …Run Code Online (Sandbox Code Playgroud) 我加入了RecyclerView我的内心NestedScrollView.基本上我希望RecyclerView与其他视图一起滚动.我面临的问题是,对于一小组数据,它工作正常,但是每当我启动活动时,对于大量数据(200个条目),它会冻结大约3-5秒然后加载.我删除了NestedScrollView它,它完美地工作,但它没有提供我想要的行为.
(有关额外信息,我正在从SQLite数据库加载数据.滚动没有问题,因为它很平滑.唯一的问题是活动冻结了一段时间)
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<... Some other Views ...>
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud) 我需要类似于此实现的行为但 NestedScrollView 将是父级, RecyclerView 将是 NestedScrollView 的子级。
例如:https : //medium.com/widgetlabs-engineering/scrollable-nestedscrollviews-inside-recyclerview-ca65050d828a
我不确定它是否可以实现。尝试在 child(RV) 滚动时禁用 parent(NSV),但是在 child 上滚动会滚动整个视图,包括 parent。
android android-scrollview android-recyclerview android-nestedscrollview
一旦运动场景结束,我在 MotionLayout 中有一个 NestedScrollView,然后 NestedScrollView 是可见的,但是当我尝试滚动视图时,没有事件会发生在 NestedScrollView。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout
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="match_parent"
app:layoutDescription="@xml/motion_scene"
tools:context=".screens.moviedetail.controller.MovieDetailFragment">
<ImageView
android:id="@+id/movieDetailPosterImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/poster_image"
android:scaleType="centerCrop"
android:src="@drawable/ic_image_24px" />
<TextView
android:id="@+id/movieDetailMovieTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/movieTitleBackground"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_vertical"
android:padding="@dimen/commonPadding"
android:text="@string/movie_title"
android:textColor="@android:color/white"
android:textSize="@dimen/commonTextSize" />
<androidx.core.widget.NestedScrollView
android:id="@+id/detailScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<TextView
android:id="@+id/movieDetailMovieOverviewHeadTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@string/movie_detail_heading_font"
android:gravity="center_vertical"
android:paddingStart="@dimen/commonPadding"
android:paddingLeft="@dimen/commonPadding"
android:paddingTop="@dimen/commonPadding"
android:paddingEnd="@dimen/commonPadding"
android:paddingRight="@dimen/commonPadding"
android:text="@string/overview"
android:textColor="@color/headTextColor"
android:textSize="@dimen/commonTextSize" />
<TextView
android:id="@+id/movieDetailMovieOverviewTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@string/movie_detail_heading_font"
android:gravity="center_vertical"
android:maxLines="@integer/overviewMaxLength"
android:paddingStart="@dimen/commonPadding"
android:paddingLeft="@dimen/commonPadding"
android:paddingEnd="@dimen/commonPadding"
android:paddingRight="@dimen/commonPadding"
android:paddingBottom="@dimen/commonPadding"
android:textColor="@color/textColor"
android:textSize="@dimen/commonTextSize" /> …Run Code Online (Sandbox Code Playgroud) 我在 NestedScrollView 中有 RecyclerView
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
我在大项目中遇到了这个问题,为了找到这个问题的解决方案,我创建了没有其他视图的新项目。
这是 MainActivity 的完整代码
class MainActivity : AppCompatActivity() {
var mItems = mutableListOf<String>()
var mAdapter = MyAdapter(mItems)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recycler.layoutManager = LinearLayoutManager(this)
recycler.adapter = mAdapter
delayedLoadDataIfPossible(100)
recycler.viewTreeObserver.addOnScrollChangedListener {
delayedLoadDataIfPossible(100)
}
}
private fun delayedLoadDataIfPossible(delay: Long) {
Observable.timer(delay, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
var scrollingReachedEnd = isScrollingReachedEnd()
if (scrollingReachedEnd) {
loadData()
}
}
}
private fun isScrollingReachedEnd(): Boolean {
val layoutManager = LinearLayoutManager::class.java.cast(recycler.layoutManager)
val …Run Code Online (Sandbox Code Playgroud)