标签: android-nestedscrollview

获取 NestedScrollView 内的第一个可见视图

我有下一个问题。

我正在尝试在 NestedScrollView 中获取第一个可见项目。实际上,里面的第一个也是唯一的视图是 LinearLayout(因为滚动视图只能容纳一个直接子视图),但我试图在其中获取第一个可见项。我搜索了很多,但没有成功。

通过这种方法,我想避免在另一个 RecyclerView 中使用 RecyclerView。我发现这是一个不好的做法。

PS 我不想使用 ListView 或 RecyclerView

提前致谢

android android-nestedscrollview

1
推荐指数
1
解决办法
2880
查看次数

NestedScrollView里面的ViewPager里面的WebView不能垂直滚动

我需要启用放置在nestescrollview中的viewpager的webview滚动,因为我正在使用CollapsingToolbarLayout.但我不能滚动它.所有工作除了WebView滚动.哪里错了?

在此输入图像描述

这是我的活动标记:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/activity_read_article"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackgroundLight"
    android:fitsSystemWindows="true"
    tools:context="ru.pwrg.revolution.activities.ReadArticleActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorBackgroundDark"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/article_cover"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                app:srcCompat="@color/colorBackgroundDark" />

        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark" />


    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

ViewPager标记的WebView片段:

<WebView android:id="@+id/article_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="8dp"
    xmlns:android="http://schemas.android.com/apk/res/android" />
Run Code Online (Sandbox Code Playgroud)

android android-webview android-viewpager android-nestedscrollview

1
推荐指数
1
解决办法
1378
查看次数

如何使用 NestedScrollView 进行分页?

当我使用嵌套滚动视图进行分页时,需要花费太多时间,有时我的应用程序会挂起?请告诉我使用嵌套滚动视图实现分页的正确方法

pagination android android-recyclerview recyclerview-layout android-nestedscrollview

1
推荐指数
1
解决办法
6685
查看次数

NestedScrollView 的 smoothScrollTo() 表现怪异

我试图实现的是滚动到scroll_position_1tab1(等)被点击喜欢这样。我根本不明白发生了什么。下面是我的布局结构。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/scroll_position_1"
                android:layout_width="0dp"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/scroll_position_2"
                android:layout_width="0dp"
                android:layout_height="wrap_content" />

        </android.support.constraint.ConstraintLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|snap">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>

        <android.support.design.widget.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>
    </android.support.design.widget.TabLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这就是我在单击选项卡时滚动但不起作用的方式:

mNestedScroller.smoothScrollTo(0, scroll_position_1_text_view.getY());    
Run Code Online (Sandbox Code Playgroud)

而将其修改为:

mNestedScroller.scrollTo(0, scroll_position_1_text_view.getY());
Run Code Online (Sandbox Code Playgroud)

工作没有问题!请帮忙。谢谢!

android android-coordinatorlayout android-nestedscrollview

1
推荐指数
1
解决办法
3160
查看次数

NestedScrollView 不滚动到底部

这种布局是我学习过程的一部分。所以请不要判断textview用于显示数据的用途。

问题是我无法滚动底部的整个数据textview。总是留下 2 组数据。如果我有 8 套,则scrollview最多显示 6 套。如果我有 4 套,它将显示 2 套并且根本不会滚动。我的有什么问题scrollview

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".FireStoreNotes">

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editText_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/title" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout2"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textInputLayout">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editText_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/description" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout3"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textInputLayout2">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editText_priority"
        android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

xml android android-layout android-nestedscrollview android-constraintlayout

1
推荐指数
1
解决办法
1092
查看次数

如何确定NestedScrollView是否滚动到最后并且是空闲的?

试过:

NestedScrollView ns =(NestedScrollView) findViewById(R.id.nested_scroll);
        ns.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

            }
        });
Run Code Online (Sandbox Code Playgroud)

但是卡住了,有没有人有想法?

只是为了清除我想要的东西 - 我希望能够观察滚动状态(如在RecyclerView的addOnScrollListener中)并且只在滚动结束(空闲)时检查一次,如果用户滚动到NestedScrollView的末尾.

android scrollview android-scrollview nestedscrollview android-nestedscrollview

0
推荐指数
2
解决办法
6258
查看次数

无法在其父NestedScrollView - Android中滚动ListView

我在ListView内部使用NestedScrollView,但看不到超过1项ListView.我可以滚动到TextView(textContact)的末尾,但不能在ListView(listContact)内滚动.

这是.xml文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    ... >
    <android.support.design.widget.CoordinatorLayout
        ... >    
        <LinearLayout
            ...
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                ... />
            <android.support.v4.widget.NestedScrollView
                ... >
                <LinearLayout
                    ...
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/textContact"
                        ... />
                    <LinearLayout
                        ...
                        android:orientation="vertical">
                        <ListView
                            android:id="@+id/listContact"
                            ... />
                    </LinearLayout>
                </LinearLayout>

            </android.support.v4.widget.NestedScrollView>

        </LinearLayout>

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        ... />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

是否有任何设计问题,此处使用的窗口小部件/控件的任何兼容性问题,或其他任何问题?

java android listview scroll android-nestedscrollview

0
推荐指数
1
解决办法
4844
查看次数

NestedScrollView中的RecyclerView填充剩余空间

我的视图层次结构如下: NestedScrollView > ConstraintLayout > [Layout,Layout, RecyclerView]

我希望我的 RecyclerView 填充 Nested ScrollView 中的剩余空间。我的ContaintLayout有wrap_content布局_高度。子布局具有以 dp 单位设置的固定高度。我想设置 RecyclerView 高度来调整 ConstraintLayout 内的剩余空间。

我以编程方式将 ConstraintLayout 的高度设置为计算值,例如两个子布局的高度 + 屏幕高度。我几乎可以工作,但是具有当前wrap_content高度的RecyclerView似乎超出了其父ConstraintLayout边界,不适合其底部边距。如果我约束到父 ConstrintLayout 的底部,那么它将移动到上面的子布局内容上。如果我设置 RecyclerView 的 0dp 高度,那么它的高度为 0dp,不会拉伸到可用空间内。也许唯一的选择是以编程方式将 RecyclerView 的高度设置为固定 dp 大小。onMeasure()、onLayout 或视图、片段等中的其他回调方法?

任何想法?

 <?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:myapp="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context=".ui.billing.BillingFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <com.domain.AppName.base.ui.billing.BillingNestedScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"

        android:overScrollMode="never"
        android:fillViewport="true"

        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        android:background="@color/theMinteFormBackground">
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <com.domain.AppName.base.utils.design.ShadowLayout
                android:id="@+id/creditCardSectionLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                myapp:sl_shadow_color="#AAD4D4D4"
                myapp:sl_shadow_angle="360"
                myapp:sl_shadow_distance="0dp"
                myapp:sl_shadow_radius="4dp" …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview android-constraintlayout

0
推荐指数
1
解决办法
2782
查看次数

显示键盘时布局不滚动且视图重叠 Android 约束布局

我遇到了一个问题,当键盘出现时,我的登录屏幕没有滚动并且视图与按钮重叠。

下面是登录布局的代码,有人可以帮助我为什么视图重叠

我在这里粘贴了登录布局文件,当打开键盘时,布局文件底部的 Linearlayout 与上面定义的 Linearlayout 重叠。并且视图没有滚动。

<data>

 <!-- databinding data here -->

</data>


<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"            
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="">

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/top_guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.25" />

        <ImageView
            android:id="@+id/img_logo_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="@+id/top_guideline"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/txt_title_m_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"                
           app:layout_constraintTop_toBottomOf="@+id/top_guideline" />

        <TextView
            android:id="@+id/txt_signin_proceed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/txt_title_m_id" />



        <RelativeLayout
            android:id="@+id/rl_olk_sign"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="25dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/txt_signin_proceed">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toStartOf="@+id/txt_olk_sign"
                android:src="@drawable/ic_olk" />

            <TextView
                android:id="@+id/txt_olk_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:padding="10dp"/>
        </RelativeLayout>

        <TextView
            android:id="@+id/txt_no_olk_credentials" …
Run Code Online (Sandbox Code Playgroud)

android overlapping android-nestedscrollview android-constraintlayout

0
推荐指数
1
解决办法
632
查看次数

折叠工具栏布局的渲染问题

我有一个项目,其中一个片段使用折叠工具栏布局。直到最近,一切都很好。但上次我在 Android Studio 中遇到了折叠工具栏布局的渲染问题。例如下面的布局示例:

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
        app:title="@string/app_name">

        
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:scaleType="centerCrop"
            android:src="@drawable/favorite"
            app:layout_collapseMode="parallax" />
        
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

    </com.google.android.material.appbar.CollapsingToolbarLayout>

</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="8sp"
        android:padding="16dp"
        android:text="this is text"
        android:textSize="20sp" />
</androidx.core.widget.NestedScrollView> </androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

问题是 NestedScrollView 在 Android Studio 中渲染后隐藏,有时在我删除下一个提示时出现:

应用程序:layout_behavior =“@ string / appbar_scrolling_view_behavior”

但它出现在片段的左上角。Android Studio 显示以下错误:

java.lang.NoClassDefFoundError: Could not initialize class androidx.core.view.accessibility.AccessibilityNodeInfoCompat$AccessibilityActionCompat
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.updateAccessibilityActions(AppBarLayout.java:1882)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.setHeaderTopBottomOffset(AppBarLayout.java:2118)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.setHeaderTopBottomOffset(AppBarLayout.java:1446)
at com.google.android.material.appbar.HeaderBehavior.setHeaderTopBottomOffset(HeaderBehavior.java:158)
at com.google.android.material.appbar.AppBarLayout$BaseBehavior.onLayoutChild(AppBarLayout.java:1781) …
Run Code Online (Sandbox Code Playgroud)

render android-layout android-studio android-collapsingtoolbarlayout android-nestedscrollview

0
推荐指数
1
解决办法
377
查看次数