我有一个使用新的CoordinatorLayout/AppBarLayout/CollapsingToolbarLayout范例的片段,我希望能够检测到折叠工具栏何时完全展开,以便我可以对它所在的整个片段执行操作,例如弹出片段离开堆栈并转到新的,解散片段.我有解雇代码工作,我只需要知道何时何时不使用它.
我已经用AppBarLayout.OnOffsetChangedListener进行了一些实验,但没有太多运气.有没有办法用它来确定什么时候完全扩展,或者有人知道更优选的方法?
提前致谢!
编辑:我也看到AppBarLayout.setExpanded(...)有几个实现,但不是AppBarLayout.getExpanded()或类似的东西,所以我也被困在那里.
android android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
我正在使用我正在使用的一个Android应用程序CoordinatorLayout,AppBarLayout并CollapsingToolbarLayout使用高级折叠栏功能.
我正在使用recyclerview来显示片段中的项目数.当我向上滚动recyclelerview时,它会平滑地折叠AppBarLayout,但当我向下滚动并到达第一项时,recyclerview它会自动停止滚动而不会扩展`AppBarLayout'.
然后我再次向下滚动以使其AppBarLayout可见.所以我的要求是当我到达recyclerview的顶部时向下滚动它必须扩展`AppBarLayout'.
我们应该怎么做.任何的想法 ?请查看相同https://www.dropbox.com/s/va5jk27ikytk5ax/app_collapsebar_issue.mp4?dl=0的视频
这是我的布局: -
<?xml version="1.0" encoding="utf-8"?>
<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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:adjustViewBounds="true"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@drawable/offer_image"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!-- <com.flaviofaria.kenburnsview.KenBurnsView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="220dp"
android:src="@drawable/offer_image" />-->
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.flaviofaria.kenburnsview.KenBurnsView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="220dp"
android:src="@drawable/offer_image" />
<FrameLayout
android:id="@+id/collapse_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B3c85a00">
</FrameLayout> …Run Code Online (Sandbox Code Playgroud) android android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
我在CollapsingToolBar里面使用CoordinatorLayout,我NestScrollView包含一些EditText作为子视图.我面临的是当edittext聚焦并且keybaoard出现时我的完整视图没有向上滚动.
下面是代码和图像作为该布局的输出.
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
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="match_parent"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/ivProductImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/stub_image"
app:layout_collapseParallaxMultiplier="0.7"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/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.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/containerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp">
<EditText
android:id="@+id/etProductTitle"
style="@style/EditTextStyle"
android:hint="@string/lbl_product_title"
android:inputType="text"
android:textSize="24dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<EditText
android:id="@+id/etProductDescription"
style="@style/EditTextStyle"
android:hint="@string/lbl_description"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android androiddesignsupport android-coordinatorlayout android-collapsingtoolbarlayout
我想创建一个如下图所示的布局:
CoordinatorLayout包含:
我想以这种方式回应滚动事件:
我在使用CollapsingToolbarLayout和TabLayout之间的RecyclerView时遇到问题.我可以在不使用RecyclerView的情况下实现这种布局(我将CollapsingToolbarLayout和TabLayout放在AppBarLayout中,将ViewPager放在它外面,在CoordinatorLayout内).
我的问题:
layout_scrollFlags和哪个layout_behavior?似乎AppBarLayout的高度有限.当我将RecyclerView放在AppBarLayout中时,只有RecyclerView的一部分可见,并且TabLayout也会消失.
android android-toolbar android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout
我正在开发一个应用程序,我正在使用带有CollapsingToolbarLayout和NestedScrollView的AppBarLayout.我已经成功实现了这个并且工作正常.
现在我想要做的是,在Nestedscrollview上进行快速刷卡时,它应该完全滚动到顶部.同样,在向屏幕底部投掷(快速向下滑动)时,它必须顺畅地滚动到底部.但是现在,它只会卡在两者之间,这使它看起来很难看.我已经尝试了许多可用的解决方案,但没有任何方法可以帮助我 我目前的设置如下.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:zhy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="RtlHardcoded">
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="246dp"
android:scaleType="fitXY"
android:tint="#11000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:padding="10dp">
<FrameLayout
android:id="@+id/back_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<ImageView
android:id="@+id/back_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha" />
</FrameLayout>
<FrameLayout
android:id="@+id/frameLayoutheart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:paddingTop="5dp">
<ImageView
android:id="@+id/favbtnicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/heart_profile" />
</FrameLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/main.framelayout.title"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.3">
<LinearLayout …Run Code Online (Sandbox Code Playgroud) android android-collapsingtoolbarlayout android-appbarlayout android-nestedscrollview
我正在使用带有viewpager的CollapsingBarLayout,并且viewpager的片段具有listview,gridview.
这是我的代码:
<?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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bigsteptech.seandroidnativeapp.classes.modules.common.ViewGroupEvent">
<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: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:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@style/TransparentText">
<FrameLayout
android:id="@+id/carouselLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<ImageView
android:id="@+id/coverImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="bottom"
android:orientation="vertical"
android:layout_gravity="bottom"
android:padding="@dimen/profile_image_margin"
android:background="@drawable/gradient_bg"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/profile_image_margin"
android:textSize="@dimen/text_size_xlarge"
android:textStyle="bold"
android:textColor="@color/white"
android:id="@+id/content_title"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginLeft="@dimen/profile_image_margin"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@color/white"
android:textSize="@dimen/text_size_medium"
android:id="@+id/category_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_toRightOf="@+id/category_title"
android:layout_marginLeft="@dimen/profile_image_margin"
android:textColor="@color/white"
android:textSize="@dimen/text_size_medium"
android:id="@+id/memberCount"/>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar" …Run Code Online (Sandbox Code Playgroud) 我想实现以下布局:
我列举了一个如何看待它的例子.
我在Cheesesquare上关注了CollapsingToolbarLayout和AppBarLayout实现的这个很好的例子 .我设法让内容使用CollapsingToolbarLayout内的地图(在布局xml中注释掉),但这不是理想的结果.
但是我没有找到任何解决方案/文档来使灰色框(见中间的内部图像)在初始位置是透明的.我希望它是透明的,以便看到地图.当用户向上滚动时,CollapsingToolbarLaoyut应该正常工作并折叠透明窗口并显示工具栏.现在,图像看起来只是白色或我给它的任何颜色.我已经尝试将颜色设置为透明,但它没有达到预期的效果.
所以我的问题是:如何在初始阶段将"CollapsingToolbarLayout"设置为透明(参见图像第1层灰框)?
这是我的布局代码.CollapsingToolbarLayout效果很好,但我看不到下面的地图.如果有可能实施将会很棒.
<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:fitsSystemWindows="true">
<!-- Layer 0 -->
<FrameLayout
android:id="@+id/overlayFragmentMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dip"
/>
<!-- Layer 1 -->
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="@style/CustomActionBar">
<!--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="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorAccent"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@color/black"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!-- Map view inside here works perfectly but is not
the deisired result -->
<!--
<FrameLayout
android:id="@+id/overlayFragmentMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dip"
app:layout_collapseMode="parallax"
/>
-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/transparent" …Run Code Online (Sandbox Code Playgroud) android transparent android-layout android-collapsingtoolbarlayout
我正在使用CoordinatorLayout这个效果:
这是布局代码:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorRootLayout"
android:background="@android:color/background_light"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/android_appbar_layout"
android:layout_width="match_parent"
android:layout_height="220dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayoutAndroidExample"
android:layout_width="match_parent"
android:background="#fff"
app:collapsedTitleGravity="left"
app:expandedTitleTextAppearance="@color/card_outline"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:expandedTitleGravity="center_horizontal"
app:contentScrim="?attr/colorPrimary"
app:statusBarScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="32dp"
app:expandedTitleMarginEnd="48dp">
<ImageView
android:id="@+id/parallax_header_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/orange_triangle"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.8"/>
<ImageView
app:expandedTitleGravity="center_horizontal"
android:id="@+id/someImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/circle"
android:layout_gravity="center_horizontal"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="-1"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="none"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/linear_layout_android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:background="@color/off_white"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="vertical">
<GridView
android:id="@+id/gridview_parallax_header" …Run Code Online (Sandbox Code Playgroud) android android-layout android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
我正在使用android支持设计'com.android.support:design:22.2.1'我的问题是当滚动没有内容时,折叠工具栏仍然启用折叠操作.如果滚动中没有内容,我需要删除视图的折叠.
我的XML:
<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: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:background="@android:color/white"
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="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<fragment
android:id="@+id/pawfile_header"
android:name="com.lightbulb.pawesome.fragments.PawfileHeaderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<fragment
android:id="@+id/pawfile_timeline"
android:name="com.lightbulb.pawesome.user_timeline.PawesomeUserTimelineFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
UDPATE问题:
我已经完成了禁用和启用视图折叠的功能.我使用这行代码来禁用折叠:
AppBarLayout.LayoutParams appbarParams = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams();
appbarParams.setScrollFlags(0);
collapsingToolbar.setLayoutParams(p);
Run Code Online (Sandbox Code Playgroud)
问题是appbar强制将scrollflags的高程设置为0.我尝试使用appbar.setElevation(0),但它没有任何效果.如何从我的appbar中删除高程?
是否可以将RecyclerView锚定到比通常位置稍高的位置,就像大多数可折叠视图上的FAB图标一样(预期结果见图1).
图片1
我尝试了以下代码但它没有给出预期的结果(参见图2了解当前结果)
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="180dp"
android:fitsSystemWindows="true"
app:expanded="true">
<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:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/bannerImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:src="@drawable/starter_screen_bg"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/categories"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:gravity="center"
>
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
图2
添加app:layout_behavior="@string/appbar_scrolling_view_behavior"将回收器视图附加到可折叠视图,然后忽略添加边距底部.
但是删除它会产生预期的结果,但是滚动视图不会按预期运行(没有视差效果),并且在背景图像滚动后滚动.
因此可以像第一张图像一样实现可折叠视图.
android material-design android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout