Tag: android nestedscrollview

Espresso,当NestedScrollView或RecyclerView在CoordinatorLayout中时,滚动不起作用

它看起来像CoordinatorLayout打破了Espresso的行为,如scrollTo()或RecyclerViewActions.scrollToPosition() 。 问题与NestedScrollView 对于这样的布局: … … 如果我尝试使用ViewActions.scrollTo()滚动到NestedScrollView内的任何视图,我发现第一个问题是,我得到一个PerformException 。 这是因为这个动作只支持ScrollView而NestedScrollView不能扩展它。 这个问题的解决方法在这里解释,基本上我们可以在scrollTo()复制代码,并改变约束来支持NestedScrollView 。 这似乎工作,如果NestedScrollView不是在CoordinatorLayout但只要你把它放在一个CoordinatorLayout滚动操作失败。 问题与RecyclerView 对于相同的布局,如果我将NestedScrollView替换为RecyclerView ,滚动也会出现问题。 在这种情况下,我使用RecyclerViewAction.scrollToPosition(position) 。 不像NestedScrollView ,在这里我可以看到一些滚动发生。 但是,它看起来像滚动到错误的位置。 例如,如果我滚动到最后一个位置,它将显示倒数第二,但不是最后一个。 当我将RecyclerView移出CoordinatorLayout ,滚动就像它应该的那样工作。 目前,由于这个问题,我们无法为使用CoordinatorLayout的屏幕编写Espresso测试。 任何人遇到同样的问题或知道解决方法?

Android NestedScrollView.smoothScrollBy()滚动太多

我有以下Kotlin代码: val scrollView = parent as? NestedScrollView scrollView?.let { it.smoothScrollTo(0, 500) } 这个代码第一次被调用的时候,滚动视图scrollY是0,并且它在y中成功的滚动了视图500。 但是,当这被称为第二次时,它将滚动另一个500(而不是在y中将其滚动到500,现在将是1000,以此类推,以便连续呼叫。 任何想法发生了什么? 当我深入研究NestedScrollView的代码(并最终进入OverScroller’s startScroll方法,最终被调用的时候,我可以看到在y轴上该调用的distance参数是0 – 因为它应该是除了第一个代码被调用)。 编辑:重要信息 – 我试图用ScrollView而不是一个NestedScrollView ,它按预期工作,但是因为我的ScrollView需要在一个SwipeRefreshLayout我需要它是一个NestedScrollView否则拉下总是刷新而不是滚动。

缩小子视图的高度相同

我试图在NestedScrollView中的TextView中显示文本,使得文本比屏幕更大,在缩小TextView后自动显示。 这是我的代码 – val content = findViewById(R.id.content) as TextView content.setText(R.string.large_text) content.viewTreeObserver.addOnGlobalLayoutListener { Log.d("Height", content.height.toString())//1584:6501 val factor = 1584f / 6501; content.scaleX = factor; content.scaleY = factor; } 我的设备屏幕高度是1584px , TextView的内容高度是6501px 问题是NestedScollView sill在缩小TextView的高度到设备屏幕高度后滚动。 我也试着在TextView和它的父类NestedScrollView上调用invalidate()和requestLayout(),但没有运气。 ScrollView保持滚动。 另外我试着扩展TextView并重写onMeasure()方法 override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) val parentWidth = MeasureSpec.getSize(widthMeasureSpec) val parentHeight = 1584// MeasureSpec.getSize(heightMeasureSpec) this.setMeasuredDimension(parentWidth, parentHeight) […]

滚动时,片段内容隐藏在BottomNavigationView后面

我已经深入研究了这一点,并且在做什么的时候感到不知所措 – 我在活动中的BottomNavigation栏截取了一个片段中的一些内容,我不知道该怎么做。 我尝试添加app:layout_behavior="@string/appbar_scrolling_view_behavior"到NestedScrollView但内容的底部(位置的名称)仍然被切断 – 这可能是一个简单的解决办法,但我不能想办法。 我的主要活动和“家”片段的XML如下所示: activity_home.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/home_screen" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/app_bar" /> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> <android.support.design.widget.BottomNavigationView android:id="@+id/bottom_nav" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="start" android:background="@color/navbarBackground" app:menu="@menu/bottom_nav_menu" /> </LinearLayout> home_fragment.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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:id="@+id/home_fragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="0dp"> <ImageView android:id="@+id/tokyo_placeholder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitStart" app:layout_constraintLeft_toLeftOf="parent" […]