所以,我是新来的,刚刚安装了 Android Studio,然后想创建一个基本的活动。但问题是他们希望我安装未通过 SDK 管理器安装的 SDK 和 Haxm。我已经尝试了很多,并使用了 Stack-overflow 中所述的所有方法来摆脱这种情况,但他们的方法都没有起作用。
AppBarLayout中的工具栏是否真的可以滚动,尽管带有"appbar_scrolling_view_behavior"的主容器没有足够的内容来真正滚动?
到目前为止我测试的内容:
当我使用NestedScrollView(带有"wrap_content"属性)作为主容器而TextView作为子容器时,AppBarLayout正常工作并且不滚动.
但是,当我使用仅包含少量条目的RecyclerView和"wrap_content"属性(因此无需滚动)时,即使RecyclerView从未收到滚动事件(使用OnScrollChangeListener测试),AppBarLayout中的工具栏也是可滚动的).
这是我的布局代码:
<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.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"
app:theme="@style/ToolbarStyle" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
具有以下效果,工具栏可滚动,虽然没有必要:
我还通过检查所有RecyclerView项目是否可见并使用RecyclerView的setNestedScrollingEnabled()方法找到了解决此问题的方法.
尽管如此,它似乎更像是我想要的错误.任何意见?:d
对于可能对我当前的解决方案感兴趣的人,我不得不将setNestedScrollingEnabled()逻辑放在Handler的postDelayed()方法中,延迟时间为5毫秒,因为LayoutManager在调用方法时总是返回-1第一个和最后一个项目是否可见.
我在onStart()方法中使用此代码(在我的RecyclerView初始化之后)以及每次发生RecyclerView内容更改后.
final LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//no items in the RecyclerView
if (mRecyclerView.getAdapter().getItemCount() == 0)
mRecyclerView.setNestedScrollingEnabled(false);
//if the first and the last item is visible
else if (layoutManager.findFirstCompletelyVisibleItemPosition() == 0
&& layoutManager.findLastCompletelyVisibleItemPosition() == mRecyclerView.getAdapter().getItemCount() …Run Code Online (Sandbox Code Playgroud) android android-xml android-coordinatorlayout android-appbarlayout
当CoordinatorLayout与a AppBarLayout和a 组合时,我有一个布局问题NavigationDrawer.
问题是,NavigationDrawer及其内容隐藏在工具栏后面.我已经做了很多研究并尝试了很多重组,但没有一个"解决方案"解决了我的问题.
可以在这个小小的Webm视频中找到演示:https://www.dropbox.com/s/i5zfc2x2ts2fws7/navigation_drawer_stackoverflow32523188.webm ? dl =0
基本风格是Theme.AppCompat.Light.NoActionBar.
我的activity_overview.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"
android:id="@+id/overview_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"
app:layout_scrollFlags="enterAlways|scroll" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusableInTouchMode="true">
<android.support.v4.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:text="@string/lorem_ipsum_long" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:headerLayout="@layout/nav_header"
app:menu="@menu/navigationdrawer_main" />
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/overview_floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_add"
app:layout_anchor="@id/overview_coordinator_layout"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="@string/fab_onscroll_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout android-coordinatorlayout android-appbarlayout android-drawer
这是我正在尝试使用以下所有元素构建的应用程序:
但是,一切正常,我希望内部水平回收视图不捕获任何垂直滚动.所有垂直滚动必须朝向外部垂直回收视图,而不是水平回滚视图,因此垂直滚动将允许工具栏根据其scrollFlag退出视图.
当我将手指放在recyclerview的"StrawBerry Plant"部分并向上滚动时,它会滚出工具栏:
如果我将手指放在水平滚动视图上并向上滚动,它根本不会滚出工具栏.
以下是我目前为止的xml布局代码.
该活动的XML布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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/fragment_container"
android:clipChildren="false">
<android.support.design.widget.CoordinatorLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
>
<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:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
style="@style/CustomTabLayout"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
的"水果"片段 XML布局(其是用于该片段编码-片段被标记在上面图片):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:visibility="gone"
android:layout_centerInParent="true"
android:indeterminate="true"/>
<!-- <android.support.v7.widget.RecyclerView-->
<com.example.simon.customshapes.VerticallyScrollRecyclerView
android:id="@+id/main_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我使用了一个名为VerticallyScrollRecyclerView的自定义类,该类跟随google在视图组中处理触摸事件的示例.它的目的是拦截和使用所有垂直滚动事件,以便它可以滚动/滚出工具栏: …
android android-layout android-recyclerview android-coordinatorlayout android-appbarlayout
之间有什么准确的区别appbar,Toolbar,Actionbar?什么时候专门使用它们?我试着找到它们,但它让我感到困惑,所以任何好友都可以向我解释它们之间的确切区别以及何时使用它们或者这是单个组件的同名吗?
android android-actionbar android-toolbar android-appbarlayout
我希望将滚动支持添加到一个单独的,可滚动的,子视图CoordinatorLayout与an AppBarLayout和CollapsingToolbarLayout.滚动RecyclerView或AppBarLayout(下面的压缩代码)时,应用栏及其内容成功滚动和折叠.但是,当尝试在LinearLayout上面启动滚动事件时RecyclerView,没有任何反应,因为LinearLayout不知道滚动或折叠视图.
我们的目标是将该LinearLayout行为作为一个粘性页眉,并且RecyclerView与该页脚AppBarLayout接收相同的滚动行为RecyclerView,类似于Spotify的随机播放/可用离线标题.事实上,如果appbar_scrolling_view_behavior layout_behavior可以应用于LinearLayout类似的,那将是很好的RecyclerView,但我想在不可滚动的视图上忽略了该行为.是否有人知道这种解决方法,不需要将LinearLayout视图作为一行实现RecyclerView?
<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.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/collapsible_app_bar_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_banner"
app:contentScrim="@color/background_content_frame"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/some_image"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/collapsible_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/slide_handle_height"
android:orientation="horizontal"
android:background="@color/slide_handle"
android:gravity="center_vertical">
<!-- three buttons …Run Code Online (Sandbox Code Playgroud) android androiddesignsupport android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
我CoordinatorLayout在我的活动页面中使用.在那里有ListViewapp栏下方.但是当我使用它ListView而不是它时它不起作用NestedScrollView.如果我把ListView里面NestedScrollView,ListView不扩大
android android-coordinatorlayout android-appbarlayout nestedscrollview
CorodinatorLayout在另一个内部CoordinatorLayout,滚动子视图也应该滚动父CoordinatorLayout.
我有一个coordinatorLayout与ViewPager包含不同Fragment,使得在Scroll将隐藏tabLayout
我有另一个coordinatorLayout有viewPager.这fragment是ViewPager父片段(父母Coordinator layout)的膨胀.
问题是onScrolling子片段childViewpager只反映在coordinator layout孩子fragment而不是父母coordinator layout,我需要做的是隐藏tablayout.
结构是:
CoordinatorLayout(p) ->(tablayout(p) & ViewPager(p) -> CoordinatorLayout(c) ->(tablayout(c) & ViewPAger(c) ->recyclerView(cc)))
p -> parent;
c -> child; cc -> child to child
Run Code Online (Sandbox Code Playgroud)
如何在滚动回收器视图上进行操作将影响协调器布局,以便工具栏tablayout(p)将被隐藏.
android android-viewpager android-coordinatorlayout android-appbarlayout
嵌套滚动视图在向下滚动时平滑滚动,但在向上滚动时它是缓慢的.向上滚动时收起工具栏(带有图像视图和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
当滚动片段内的recyclerview时,我正试图让工具栏在滚动时折叠.首先,继承我的主要布局:
<DrawerLayout>
<RelativeLayout
android:id="@+id/mainRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="5dp"
app:layout_scrollFlags="scroll|enterAlways"
>
</Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
<!-- ignore -->
<drawercontents>
</DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
所以你可能猜到我的片段被加载进去了@id/container.我的第一个片段包含recyclerview,我设置app:layout_behavior="@string/appbar_scrolling_view_behavior"了recyclelerview.这确实有效,工具栏在滚动时折叠.问题是工具栏覆盖了片段未折叠时的顶部内容.在片段容器中添加一个等于工具栏大小的上边距只会在工具栏崩溃时(显然)导致留下空白.
什么不见了?有任何想法吗?
编辑:根据要求,这是包含recyclerview的片段的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:id="@+id/feed"
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:background="#00000000"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
Run Code Online (Sandbox Code Playgroud) android android-layout android-toolbar android-coordinatorlayout android-appbarlayout