我将 CoordinatorLayout 与 CollapsingToolbarLayout 一起使用。我试图将 LinearLayout 放在 AppBarLayout 下方和滚动内容上方,并且我希望该 LinearLayout 始终固定在屏幕上(AppBarLayout 是否隐藏),而不是随内容滚动。
这可能吗?
到目前为止,我有以下代码:
<android.support.design.widget.CoordinatorLayout
android:layout_above="@+id/linearLayout"
tools:context="..."
android:layout_width="wrap_content"
android:layout_height="match_parent">
<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:theme="@style/AppTheme.AppBarOverlay"
android:minHeight="200dp"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/imagemView"
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:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
>
<ImageButton
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/back_button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="18dp"
android:textSize="25sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|left|end"
android:layout_margin="@dimen/fab_margin"
app:borderWidth="0dp"
app:layout_behavior="myBehavior"/>
<include
layout="@layout/content_scrolling" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-collapsingtoolbarlayout android-appbarlayout
我在堆栈溢出中发现了这个问题,但没有适当的解决方案.
通过滚动隐藏后以编程方式显示工具栏(Android设计库)
我在工具栏中有一个自定义视图,当我向上和向下滚动时,工具栏将显示和隐藏.
当我向上滚动时,工具栏将隐藏,我在ActionBar菜单中显示一个图标.当我点击该菜单时,我想显示隐藏的工具栏,其内容具有相同的动画.
我试着翻译工具栏但没用.
这是我的自定义视图工具栏代码.
<?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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="15dp"
android:background="@drawable/searchbox_bg"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:hint="@string/home_search_hint"
android:maxLines="1"
android:textSize="15dp"
android:singleLine="true"
android:id="@+id/home_search"
android:drawableStart="@android:drawable/ic_menu_search"
android:drawableLeft="@android:drawable/ic_menu_search"
android:drawablePadding="3dp"
android:drawableTint="@color/gray_2"
android:drawingCacheQuality="high"
android:paddingLeft="10dp"
android:background="@drawable/searchbox_bg"
android:layout_weight="2"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:id="@+id/home_speak"
android:background="@drawable/searchbox_bg"
android:src="@android:drawable/ic_btn_speak_now"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/transparent"
android:visibility="invisible"/>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
android android-toolbar android-recyclerview android-coordinatorlayout android-appbarlayout
我的应用程序有一个Activity带TabLayout,和3 Fragments.在Activity's布局,我都CoordinatorLayout用ViewPager.我也需要动画工具栏.现在在Fragments布局中,我需要在底部放置一个固定的TextView.下面给出的是XML活动和片段.
我面临的问题是,
TextView在Fragment的布局中修复的问题是在底部导航栏下面并且也在滚动,我不想要.
怎么能实现这个?
activity.xml
<?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/clMain"
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="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#FFFFFF"
android:textSize="22sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
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)
fragment.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:layout_width="match_parent"
android:layout_height="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-viewpager material-design android-coordinatorlayout android-appbarlayout
当向上滚动并向下滚动时,我无法理解应用于工具栏或折叠工具栏的这两个滚动标记之间的区别
java android android-toolbar android-collapsingtoolbarlayout android-appbarlayout
在recyclerview中单击某个项目时,我会调用它
appbar.removeView(tabs)
该视频显示了会发生什么
它似乎完全删除TabLayout没有动画,然后将其添加回来,然后使用动画删除它.我放慢了转变速度,以显示它的作用.
当像这样添加它们时也会发生这种情况
if (tabs.parent != null) {
(tabs.parent as ViewGroup).removeView(tabs)
}
appbar.addView(tabs)
appbar.setExpanded(true, true)
Run Code Online (Sandbox Code Playgroud)
这是我的布局
<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/coordinator_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
app:elevation="0dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/MyToolbar"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextAppearance="@style/TabText"
android:layout_marginRight="@dimen/small_spacing"
android:layout_marginLeft="@dimen/small_spacing"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorHeight="2dp"
app:layout_scrollFlags="enterAlways"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appbar"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<***.***.CustomViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 我正在使用,android.support.design.bottomappbar.BottomAppBar但是添加选项菜单时导航图标位于左上角。
不带Option的情况下,其工作正常(center_vertical)。
带有选项菜单
没有选项菜单
谁能告诉我如何解决它?
android android-layout android-appbarlayout android-bottomnav bottombar
我有问题,我的RecyclerView在AppBarLayout后面被切断了
这是我的XML
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/root_coordinator"
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="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_tool_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:color="@android:color/white"
app:contentScrim="@color/blue_grey_900"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ProgressBar
android:id="@+id/loadingProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="snap|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/activity_vertical_margin"
android:src="@android:drawable/ic_menu_share"
app:layout_behavior="irisrecognition.example.com.irisrecognition.adapter.ScrollAwareFABBehavior" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_main" />
Run Code Online (Sandbox Code Playgroud)
如何设置的图标(家庭和溢出菜单图标)的颜色在Toolbar/ AppBarLayout 编程?
我想更改活动中单个片段的工具栏颜色方案.将AppBarLayout背景设置为浅色(例如浅灰色appBarLayout.setBackgroundResource(..);)会产生白色图标和白色标题,几乎看不到.
其布局如下:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ToolbarStyle"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
android material-design android-toolbar android-appbarlayout
我正在尝试为我的布局实现视差效果.它有效,但我还需要一件事.这是我的代码
<?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:id="@+id/coordinator_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_main"
android:layout_width="match_parent"
android:layout_height="@dimen/height_toolbar_header_experiment_result"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<ImageView
android:id="@+id/image_view_tab_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/experiment_result_header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.3"
android:background="@android:color/black"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:layout_marginBottom="?actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/whitesmoke"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_main"
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)
这工作正常,但我只能在滑动标题ImageView(image_view_tab_header)时滚动/折叠工具.当我尝试向内滑动ViewPager它不会折叠工具栏.只有当我尝试在标题内部向上滑动时.
如何在viewpager中滑动时启用工具栏的折叠?
谢谢
android android-fragments android-viewpager android-collapsingtoolbarlayout android-appbarlayout
I recently refactored my project to androidx. but now it has a fatal exception.when i run the project i face the error with coordinatorlayout and appbarLayout and incompatible with androidx. I guess I have to use an androidx alternative for AppBarLayout but I searched for it and can't find any alternative.
android.view.InflateException: Binary XML file line #36: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior
Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior
Run Code Online (Sandbox Code Playgroud)
this is my xml code:
<?xml version="1.0" encoding="utf-8"?> …Run Code Online (Sandbox Code Playgroud)