【问题标题】:Scollview inside AppBarLayout is not scrollableAppBarLayout 内的 Scrollview 不可滚动
【发布时间】:2015-12-16 16:03:14
【问题描述】:

抱歉暂时没有编写android应用程序,过去我使用带有linearlayout的Scrollview并且视图是可滚动的

但是,现在它使用 coordinatorlayout 和 appbarlayout

我尝试了scrollview,但是里面的内容是不可滚动的,所以我在网上找到了一些讨论是使用nestscollview,但仍然没有运气,如何解决它?

<android.support.design.widget.AppBarLayout
    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:popupTheme="@style/AppTheme.PopupOverlay" />

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

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:orientation="vertical">




            <TextView
                android:id="@+id/first"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="00:10 When loading an HLS/MP3 stream the current position almost always returns 5-15s in to the stream."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/second"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="00:30 I'm streaming an HLS/MP3 source, starting from zero and setting the setPlayWhenReady to true from the beginning."
                android:textSize="18sp" />


            <TextView
                android:id="@+id/third"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:00 Debug print outs show the when we receive STATE_READY in onPlayerStateChanged the current position returns almost all the time 5-15 seconds into the stream when it in fact should be 0."
                android:textSize="18sp" />


            <TextView
                android:id="@+id/fourth"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/five"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/six"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

            <TextView
                android:id="@+id/seven"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:text="01:30 When listening to the same stream, but downloaded, it reports 0 (zero) och getCurrentPosition."
                android:textSize="18sp" />

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>


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

非常感谢

【问题讨论】:

    标签: android scroll android-scrollview android-appbarlayout


    【解决方案1】:

    您需要CoordinatorLayoutNestedScrollView 中的标签app:layout_behavior="@string/appbar_scrolling_view_behavior" 才能滚动,所以您的布局如下所示:

    <?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"
        xmlns:card="http://schemas.android.com/tools"
        android:id="@+id/rootLayout"
        android:fitsSystemWindows="true">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="380dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp"
                android:fitsSystemWindows="true">
    
           <!-- Toolbar and ImageView... or other -->
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
         <!-- Your TextView -->
    
        </android.support.v4.widget.NestedScrollView> 
    
    </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

    • 如果我想在 CollapsingToolbarLayout 中有这个 nestedScrollView 怎么办。
    • 我有一些类似的布局----- 而不是 NestedScrollView (如放置在你的 ans 中)我有 RecyclerView 和 CollapsingToolbarLayout 我有 NestedScrollView 和工具栏。在这样的位置,我无法滚动嵌套滚动项目
    猜你喜欢
    • 2013-09-19
    • 2015-09-18
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 2020-06-04
    相关资源
    最近更新 更多