标签: android-nestedscrollview

如何实现具有两个固定视图的“双”折叠工具栏

我正在尝试实现如图所示的布局。
这就是我希望它工作的方式
所以我希望在用户滚动到某个点后有两个固定在屏幕顶部的视图。其他视图应该折叠起来,直到完全隐藏为止(视图 3 除外,它基本上是布局的主视图。到目前为止,我已经尝试了几种方法。其中一种比较
有效,是将折叠工具栏与可固定视图 1 和Pinnable View 2 锚定到其他视图(我附上了代码片段,这样你就知道我实现了什么)。这种方法的问题是,因为这些可固定视图不在nestedScrollView内部,所以当用户使用时不可能滚动从这两个视图开始滚动,
所以我的问题是,使用我当前的方法是否可以达到预期的效果,或者是否有其他方法可以做到这一点?

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar_layout_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <View
                android:id="@+id/view_1"
                android:layout_width="match_parent"
                android:layout_marginBottom="32dp"
                android:layout_height="200dp"
                android:background="#0071BD"
                app:layout_collapseMode="parallax">
            </View>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:layout_marginTop="32dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".ScrollingActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <View
                android:id="@+id/view_2"
                android:layout_width="wrap_content"
                android:background="#5495BD"
                android:layout_height="300dp"/>

            <View
                android:id="@+id/pinnable_view_2_anchor_view"
                android:layout_width="match_parent"
                android:layout_height="41dp"
                android:background="@null" />

            <View
                android:id="@+id/view_3"
                android:layout_width="match_parent"
                android:background="#57B1BC"
                android:layout_height="1000dp" />
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

    <View
        android:id="@+id/pinnable_view_1"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="#00015E"
        android:nestedScrollingEnabled="true"
        app:layout_anchor="@id/app_bar_layout_view"
        app:layout_anchorGravity="bottom">
    </View>

    <View …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-collapsingtoolbarlayout android-nestedscrollview

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

我怎样才能在NestedScrollView中有一个ListView

我创建了一个带有页面的应用程序,需要从Web服务动态加载内容.我希望listview能够与NestedScrollView中的线性布局一起滚动.但是当内容加载到列表视图时,它不会延伸到其完整高度.

这是我的代码.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.myquestionth.myquestionth10.Profile2Activity"
    tools:showIn="@layout/activity_profile2">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:background="#BBBBBB" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Media heading"
                android:id="@+id/textView2" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis."
                android:id="@+id/textView8" />

        </LinearLayout>

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#70bcf5" />

    </LinearLayout>

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

我有一些关于scrollview的搜索无法嵌套.根据我在Google Play评论页面设计的布局,这是我想要的一个例子.他们使用的方法是什么?建议我,如果我做错了什么.非常感谢.

在此输入图像描述

这就是我想要的.

在此输入图像描述

java layout android listview android-nestedscrollview

6
推荐指数
2
解决办法
1万
查看次数

RecyclerView滚动不适用于NestedScrollView

我有一个布局,我有一个NestedScrollView包含一个图像,多个按钮和一个RecycleView.

当我说recycleView.smoothScrollToPositionrecycleView.scrollToPosition()时,它现在什么都不做.拒绝滚动甚至像素.如果我删除NestedScrollView它工作正常,但万一我失去了对周围区域的滚动效果.

你们之前有没有遇到过这个问题?

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="world.the.rule.com.testtollbarstuff.ScrollingActivity">

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


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="none"
        app:popupTheme="@style/AppTheme.PopupOverlay" />


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

<android.support.design.widget.CollapsingToolbarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"
    app:layout_scrollFlags="scroll">

    <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"
            app:layout_collapseMode="parallax">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:clickable="true"
                android:src="@drawable/mock_image" />

            <include layout="@layout/content_scrolling" />

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CollapsingToolbarLayout>
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview

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

NestedScrollview内的Recyclerview scrollTo位置不起作用

当我在NestedScrollView中使用RecyclerView时,我使用scrollTo()固定位置,它不起作用.

(rlv_brandWithLetter.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(index, 0)
rlv_brandWithLetter.smoothScrollToPosition(index)
Run Code Online (Sandbox Code Playgroud)

我读了源代码NestedScrollView,该方法scrollTo()已执行.

@Override
public void scrollTo(int x, int y) {
    if (getChildCount() > 0) {
        View child = getChildAt(0);
        x = clamp(x, getWidth() - getPaddingRight() - getPaddingLeft(), child.getWidth());
        y = clamp(y, getHeight() - getPaddingBottom() - getPaddingTop(), child.getHeight());
        if (x != getScrollX() || y != getScrollY()) {
            super.scrollTo(x, y);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

x != getScrollX() || y != getScrollY()总是回来false,这是我发现的线索.

有没有人遇到过这个问题?

android android-recyclerview android-nestedscrollview

6
推荐指数
0
解决办法
366
查看次数

adjustPan和NestedScrollView的交互

在我的布局中,我有EditText一个NestedScrollView.当EditText用软键盘编辑,我想NestedScrollView的内容被向上滚动.但是,相反,活动的全部内容都会滚动,包括ImageView不应移动的内容:

之前 后

我想要什么(糟糕的Gimp-job):

在此输入图像描述

以下是我的布局的简化版本仍然存在问题:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            app:srcCompat="@mipmap/ic_launcher" />

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:isScrollContainer="true"
            android:paddingTop="150dp">

            <LinearLayout
                android:id="@+id/layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Aaa aaaaaaaaaa aaa aaaaaaaa aaaa. Aaa aaaaaaa aaa aa aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa:Aaa aaaaaaaaaa aaa aaaaaaaa aaaa. Aaa aaaaaaa aaa aa aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa: Aaa …
Run Code Online (Sandbox Code Playgroud)

android scrollview android-softkeyboard android-nestedscrollview

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

Nestedscrollview/Scrollview内的Webview缺少内容

我有一个webview,它放在nestedscrollview中.我面临的问题是webview没有加载整页.相反,它会加载页面的一部分,然后将底部空白保留为空白(白色).

我也试过了scrollview.

输出我得到:

输出我得到了

我的webview代码:

private ImageButton backButton;
    private WebView webView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article);

        backButton = findViewById(R.id.backButton);
        webView=(WebView)findViewById(R.id.webView);
        webView.setWebViewClient(new MyBrowser());
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//            descriptionView.setText(Html.fromHtml(data, Html.FROM_HTML_MODE_COMPACT));
//        } else {
//            descriptionView.setText(Html.fromHtml(data));
//        }
        webView.getSettings().setJavaScriptEnabled(true);

        webView.loadUrl("file:///android_asset/html/test.html");

        backButton.setOnClickListener(this);
    }

    private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
Run Code Online (Sandbox Code Playgroud)

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activities.ArticleActivity">


    <RelativeLayout
        android:id="@+id/topBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"> …
Run Code Online (Sandbox Code Playgroud)

android android-webview android-nestedscrollview

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

Android:自定义底部对话框

如何使用android标准组件底页实现以下设计功能:

  1. 底部工作表对话框片段出现时的图像:

在此输入图像描述

  1. 用户向上滚动以查看内容底部时的图像:

在此输入图像描述

我将使用ViewPager滚动标题图像和RecyclerView来显示描述和其他信息.当垂直滚动内容时,对ImageView(放置在ViewPager中)的视差效果.拥有ImageView(和ViewPager)的最小高度,用户无法完全折叠它(查看第二个截图,这是用户滚动直到内容结束).

我想在它达到最小高度时停止滚动ImageView(看第二个截图),但下面的ImageView内容应该继续滚动

dialog fragment parallax android-nestedscrollview bottom-sheet

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

在Constraint布局中使用NestedScrollView时出现问题

我在NestestScrollView中使用Constraint布局,如下所示.

<?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:id="@+id/clProfileFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/appCompatImageView8"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:scaleType="centerCrop"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHeight_percent="0.7"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@mipmap/bg_nature" />


<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ivProfileFragment"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:src="@drawable/ic_profile"
    android:visibility="visible"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/tvUserName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:fontFamily="@font/raleway_medium"
    android:letterSpacing="0.2"
    android:textAlignment="center"
    android:textColor="@color/darkBlue"
    app:layout_constraintBottom_toBottomOf="@+id/ivProfileFragment"
    app:layout_constraintStart_toEndOf="@+id/ivProfileFragment"
    app:layout_constraintTop_toTopOf="@+id/ivProfileFragment"
    tools:text="Mehul Kanzriya" />


<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/ivCloseProfileFragment"
    style="@style/VectorImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_close" />

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:fillViewport="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/ivProfileFragment"
    app:layout_constraintBottom_toTopOf="@id/button">

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

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="8dp" …
Run Code Online (Sandbox Code Playgroud)

android android-nestedscrollview android-constraintlayout

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

BottomSheet Fragment底部工作表布局中存在的NestedScrollview中的滚动行为问题

我的场景是按钮点击我需要打开一个底部展开的底部,当我们向上拖动时它应该像collasping工具栏一样.

这里Appbar的行为与Bottomsheet同步,但不知何故,NestedScrollview行为只与Collasping工具栏同步,而不是Bottomsheet行为.

当我在NestedScrollview上滚动它只是扩展和压缩工具栏而不是BottomSheet.

下面是底部布局:

<?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:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:elevation="@dimen/design_appbar_elevation"
    android:layout_height="match_parent"
    app:layout_behavior="@string/bottom_sheet_behavior"

    app:behavior_hideable="true"

    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:fitsSystemWindows="true"
        android:layout_height="192dp"
        android:layout_width="match_parent"

        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:toolbarId="@+id/toolbar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            android:fitsSystemWindows="true"

            app:contentScrim="?attr/colorPrimary">

            <ImageView
                android:id="@+id/app_bar_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax"
                android:src="@drawable/ic_launcher_background"
                android:scaleType="centerCrop" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent">


            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

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

            <EditText
                android:id="@+id/editText"
                android:layout_width="222dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <EditText
                android:id="@+id/editText2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name"
                app:layout_constraintEnd_toEndOf="@+id/editText"
                app:layout_constraintStart_toStartOf="@+id/editText" …
Run Code Online (Sandbox Code Playgroud)

android android-appbarlayout android-nestedscrollview bottom-sheet android-bottom-nav-view

6
推荐指数
0
解决办法
1254
查看次数

嵌套的Expandable RecyclerView滞后于“展开”和“折叠”,子项目数量过多

我在应用中创建了可扩展的回收视图,如下所示

它具有父项目菜单类别,而类别具有子项目,如图所示

在此处输入图片说明

以下是我的适配器代码的一部分。

 public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
    if (i > HEADER_COUNT - 1) {
        FoodMenuItem foodMenuItem = foodMenuItems.get(i - HEADER_COUNT);
        MenuViewHolder menuViewHolder = (MenuViewHolder) viewHolder;
        //menuViewHolder.rvMenu.setLayoutManager(new LinearLayoutManager(viewHolder.itemView.getContext(), LinearLayoutManager.VERTICAL, false));
        if (isVegOnly) {
            List<Item> items = new ArrayList<>();
            for (Item item : foodMenuItem.getItems()) {
                if (item.getType().equalsIgnoreCase(Item.FOOD_TYPE_VEG)) {
                    items.add(item);
                }
            }
            menuViewHolder.rvMenu.setAdapter(new FoodMenuChildRecycler(items, foodMenuParentListener, i, isAddAllowed));
            menuViewHolder.tvNumItems.setText("(" + items.size() + " items)");

        } else {
            menuViewHolder.rvMenu.setAdapter(new FoodMenuChildRecycler(foodMenuItem.getItems(), foodMenuParentListener, i, isAddAllowed));
            menuViewHolder.tvNumItems.setText("(" + foodMenuItem.getItems().size() + " items)"); …
Run Code Online (Sandbox Code Playgroud)

android recycler-adapter android-recyclerview expandablerecyclerview android-nestedscrollview

6
推荐指数
0
解决办法
576
查看次数