相关疑难解决方法(0)

如何在NestedScrollView中使用RecyclerView?

RecyclerView里面怎么用NestedScrollViewRecyclerView设置适配器后内容不可见.

UPDATE布局代码已更新.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/keyline_1">

    </RelativeLayout>

    <View
        android:id="@+id/separator"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#e5e5e5" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/conversation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

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

android android-recyclerview

189
推荐指数
13
解决办法
17万
查看次数

需要针对某些片段禁用针对CollapsingToolbarLayout的扩展

我有一个AppCompatActivity控制替换许多片段.这是我的布局.

activity_main.xml中

<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_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">

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

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:background="@color/white"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer"/>

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

activity_main_frame.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: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="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:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

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

            <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.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:layout_gravity="bottom"/>

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

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >
    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/appbar" …
Run Code Online (Sandbox Code Playgroud)

android android-support-library android-toolbar coordinator-layout

53
推荐指数
7
解决办法
4万
查看次数

如何避免CollapsingToolbarLayout在滚动时没有被捕捉或"摇摆"?

背景

假设您创建的应用程序具有与您通过"滚动活动"向导创建的应用程序类似的UI,但您希望滚动标记具有捕捉功能,如下所示:

<android.support.design.widget.CollapsingToolbarLayout ... app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" >
Run Code Online (Sandbox Code Playgroud)

问题

事实证明,在许多情况下,它存在捕捉问题.有时UI不会捕捉到顶部/底部,使得CollapsingToolbarLayout保持在两者之间.

有时它也会尝试捕捉到一个方向,然后决定捕捉到另一个方向.

您可以在此处查看所附视频的两个问题.

我试过的

我认为这是我在RecyclerView上使用setNestedScrollingEnabled(false)时遇到的问题之一,所以我在这里问了一下,但后来我注意到即使使用解决方案也没有使用此命令,甚至在使用时一个简单的NestedScrollView(由向导创建),我仍然可以注意到这种行为.

这就是为什么我决定这个报告是一个问题,在这里.

可悲的是,我找不到StackOverflow上那些奇怪错误的解决方法.

这个问题

为什么会发生,更重要的是:如何在仍然使用它应该具有的行为的同时避免这些问题?


编辑:这是一个很好的改进Kotlin版本的接受答案:

class RecyclerViewEx @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : RecyclerView(context, attrs, defStyle) {
    private var mAppBarTracking: AppBarTracking? = null
    private var mView: View? = null
    private var mTopPos: Int = 0
    private var mLayoutManager: LinearLayoutManager? = null

    interface AppBarTracking {
        fun isAppBarIdle(): Boolean
        fun isAppBarExpanded(): Boolean
    }

    override fun dispatchNestedPreScroll(dx: …
Run Code Online (Sandbox Code Playgroud)

android android-collapsingtoolbarlayout

27
推荐指数
3
解决办法
4396
查看次数

如果不需要,防止CollapsingToolbarLayout崩溃

使用:

compile 'com.android.support:design:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
Run Code Online (Sandbox Code Playgroud)

随着Cheesesquare项目的更新.

进入奶酪的细节,我删除2张牌(只有一张).有没有办法防止显示空白空间的工具栏折叠?

在此输入图像描述

android android-support-library android-toolbar android-collapsingtoolbarlayout

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

滚动没有内容时如何禁用CollapsingToolbar崩溃?

我正在使用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中删除高程?

android scroll toolbar android-collapsingtoolbarlayout

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

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