我尝试添加许多应用程序所显示的相同功能,其中屏幕的上部区域根据滚动内容缩小和扩展.
为此,我使用了Google的设计库,如CheeseSquare示例所示.
事实是,无论NestedScrollView中有多少内容,它都允许我在内容的最后一个视图下方滚动,只是为了让我看到动作栏的最终状态,具有最小的自身大小.
简而言之,这是我在滚动到底部时看到的内容(CheeseSquare示例的修改内容):
虽然这是滚动到底部时我想要的(从联系人应用程序中获取):
我也试图修复ThreePhasesBottomSheet示例中的一个错误,即使它处于窥视状态,滚动底部内容也是可能的.要重现,请开始水平滚动(这不会做任何事情,因为没有任何东西可以滚动),然后垂直滚动,这会以某种方式触发底部内容的滚动.
因此,我需要在"transformView()"方法中禁用滚动,在"翻译"的情况下
这是使用正常用法的方式:
这就是它如何处理不阻止滚动的错误:
我试图使用" layout_scrollFlags "标志,将高度更改为wrap_content,并删除clipToPadding和fitsSystemWindows属性.
这是示例XML文件,我已将其修改为仅包含一个cardView而不是多个:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</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"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Info" …Run Code Online (Sandbox Code Playgroud) android material-design android-design-library android-collapsingtoolbarlayout nestedscrollview
通过创建NestedScrollView,您可以将滚动视图放在另一个滚动视图中,只要这些视图正确实现NestedScrollingChild和NestedScrollingParent.
(这是一个不错的设计模式"Ian Lake(来自Google)实际上建议在RecyclerView这里放置一个nestedscrollview:plus.google.com/u/0/+AndroidDevelopers/posts/9kZ3SsXdT2T")
我想将RecyclerView放在NestedScrollView中,幸运的是RecyclerView实现了NestedScrollingChild,因此您可以将它放在NestedScrollView中.
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild
Run Code Online (Sandbox Code Playgroud)
我看过这些帖子:
如何在NestedScrollView中使用RecyclerView?
NestedScroll与NestedScrollView,RecyclerView(水平),在CoordinatorLayout内
但是大多数投票解决方案的问题是,它调用所有项目,RecyclerView例如,如果它是无尽的RecyclerView,当用户到达列表的末尾时,您想要发出网络请求,然后使用该解决方案RecyclerView重复调用服务器因为它会自动到达最后一项RecyclerView.
无论如何,如何设置参数,以便我可以放入RecyclerView内部NestedScrollView.(实际上我想将一个像framelayout或relativelayout这样的视图组作为nestedscrollview的单个childe然后我想将recyclelerview放在framelayout或relativelayout中)
当我放在RecyclerView里面NestedScrollView没有什么可以显示.
要创建示例项目,您可以使用cheesesquare并更改CheeseDetailActivity为具有RecyclerView.
虽然BNK的答案不正确,但BNK已经尝试了很多.所以我授予他赏金.还在寻找好的解决方案....
我在RecyclerView里面用NestedScrollView.我也设置setNestedScrollingEnabled为假recyclerview
支持较低的API
ViewCompat.setNestedScrollingEnabled(mRecyclerView, false);
现在!当用户滚动视图时,每件事似乎都没问题,但是!!! recyclerview中的视图不回收!和堆大小迅速增长!!
更新:RecyclerView布局管理器是StaggeredLayoutManager
fragment_profile.xml:
<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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/profileSwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- RecyclerView and NestedScrollView -->
<include layout="@layout/fragment_profile_details" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
fragment_profile_details.xml:
<LinearLayout
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/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical" >
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scrollbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/nested_scrollbar_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<android.support.v7.widget.CardView
android:id="@+id/profileCardview"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我有XML,这consits的DrawerLayout,CoordinatorLayout有custom views,AppBarLayout,NestedScrollView.
问题:当NestedtScrollView填充内容时,NestedtScrollView向下滚动.所有的研究,如scrollView.setScrollY(0)定制课程都layout_behavior = FixedScrollingViewBehavior没有帮助我.
我该如何阻止这种滚动
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@color/semitransparet_color_primary">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/actionbar_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:elevation="4dp"/>
</android.support.design.widget.AppBarLayout>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/product_scroll_wrpr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
// my content is here
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) 我在NestedScrollview中有一个Recyclerview ..一切正常,除了一个thig.我在NestedScrollview中有三个视图,前两个是LinearLayout然后是Recyclerview.当我运行我的应用程序时,活动不显示前两个布局,它从Recyclerview的顶部开始.
它如何显示我的布局:
它的假设如何显示:
我在viewpager下加载这个enite布局,我的viewpager是Coordinator Layout的子代.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/home_layout_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/image_slider"
android:layout_width="match_parent"
android:layout_height="@dimen/image_slider_height"
android:layout_marginTop="@dimen/image_slider_top_margin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/popular_fragment_side_padding"
android:layout_marginRight="@dimen/popular_fragment_side_padding"
android:layout_marginTop="@dimen/popular_fragment_side_padding"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/free_delivery"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="@color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/btnImageViewFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/icon_free_delivery" />
<TextView
android:id="@+id/btnTextFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnImageViewFreeDelivery"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="@string/free_delivery_txt"
android:textColor="@color/popular_fragment_four_btn_txt"
android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/flash_deals"
android:layout_width="76dp"
android:layout_height="76dp" …Run Code Online (Sandbox Code Playgroud) 我CoordinatorLayout在我的活动页面中使用.在那里有ListViewapp栏下方.但是当我使用它ListView而不是它时它不起作用NestedScrollView.如果我把ListView里面NestedScrollView,ListView不扩大
android android-coordinatorlayout android-appbarlayout nestedscrollview
我有一个NestedScrollView包含一个LinearLayout和一个RecyclerView(都在RelativeLayout内).
<android.support.design.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">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scroll">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lay_account">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:paddingTop="10dp"
android:id="@+id/lay_total"
android:paddingBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/total"
android:id="@+id/lblTotal"
android:textSize="@dimen/text_medium"
android:layout_marginLeft="20dp"
android:textColor="@color/dark_eurakostheme_color"
android:textStyle="bold"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtTotalAmount"
android:textSize="@dimen/text_extra_extra_large"
android:gravity="center_horizontal"
android:textColor="@color/eurakostheme_color"/>
<ImageView
android:layout_width="@dimen/icon_extra_extra_large"
android:layout_height="match_parent"
android:id="@+id/imageView3"
android:src="@drawable/coin_eurakos"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="@+id/divisor"
android:background="@color/dividerColor"
android:layout_alignBottom="@+id/lay_total"/>
<android.support.v7.widget.RecyclerView
android:layout_below="@id/lay_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rclBasketAmounts"
android:background="@android:color/white"
android:padding="10dp">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
将数据加载到RecyclerView后,我需要以编程方式更改它的高度,如下所示:
RelativeLayout.LayoutParams lay_params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
50 + ((int) (baskets.length * getResources().getDimension(R.dimen.list_height_small))));
lay_params.addRule(RelativeLayout.BELOW, …Run Code Online (Sandbox Code Playgroud) 嵌套滚动视图在向下滚动时平滑滚动,但在向上滚动时它是缓慢的.向上滚动时收起工具栏(带有图像视图和framelayout)不会呈现其内容(保持空白).我在折叠工具栏中尝试了每个标志.
<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/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/pic"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/>
<include
android:id="@+id/framelayout"
layout="@layout/header_layout"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:minHeight="100dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- Your Scrollable View -->
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#da1b75"
android:orientation="horizontal"
android:textColor="#ffffff"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_anchor="@id/appbar"
app:layout_collapseMode="pin"
app:title="">
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
android android-support-library android-collapsingtoolbarlayout android-appbarlayout nestedscrollview
我正在使用我正在使用的一个Android应用程序CoordinatorLayout,AppBarLayout并CollapsingToolbarLayout使用折叠工具栏功能.
我NestedScrollView在布局中使用AppBarLayout以相同的布局展开和折叠.当我试图从屏幕中心向上滚动然后它不起作用但是当我尝试从屏幕右上角向上滚动屏幕时它会顺利滚动.
下面提到的是我的xml文件
layout.xml
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fragment_back_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/new_recharge" />
<com.spiceladdoo.views.RobotTextviewRegular
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="NEW PAYMENT"
android:textColor="@color/offer_name_text_color" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@color/white"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp">
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal">
<LinearLayout …Run Code Online (Sandbox Code Playgroud) 我有一个垂直的nestedscrollview,其中包含一堆带有水平布局管理器设置的recyclerview.这个想法非常类似于新的谷歌游戏商店的外观.我能够使它起作用,但它根本不光滑.以下是问题:
1)水平回收视图项目大多数时间都无法拦截触摸事件,即使我点击它也是如此.滚动视图似乎优先于大多数动作.我很难在水平运动上找到钩子.这个用户体验令人沮丧,因为我需要在它工作之前尝试几次.如果你检查游戏商店,它能够很好地拦截触摸事件,它只是运作良好.我注意到在游戏商店中他们设置的方式是在一个垂直的回收者视图中的许多水平回收视图.没有滚动视图.
2)水平回收视图的高度必须手动设置,并且没有简单的方法来计算子元素的高度.
这是我正在使用的布局:
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:background="@color/dark_bgd"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="gone"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/starring_list"
android:paddingLeft="@dimen/spacing_major"
android:paddingRight="@dimen/spacing_major"
android:layout_width="match_parent"
android:layout_height="180dp" />
Run Code Online (Sandbox Code Playgroud)
此UI模式非常基本,很可能在许多不同的应用程序中使用.我已经阅读了许多SO,其中ppl说将列表放在列表中是一个坏主意,但它是一个非常普遍和现代的UI模式在整个地方使用.想看netflix就像界面里面有一系列水平滚动列表垂直清单.有没有一个顺利的方法来实现这一目标?
来自商店的示例图片:
android horizontal-scrolling android-recyclerview nestedscrollview