[android]Scollview AppBarLayout 内的不可滚动

发布时间: 2016/9/26 3:53:02
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

对不起,不编程 android 应用程序一段时间,在过去我使用 Scrollviewlinearlayoutview 是可滚动

然而,现在它使用的 coordinatorlayout 和 appbarlayout

我试过 scrollview ,但里面的内容不是 scorllable,所以找了一些在线的讨论是使用 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>

多谢

解决方法 1:

你需要 CoordinatorLayoutNestedScrollViewtag app:layout_behavior="@string/appbar_scrolling_view_behavior" 是可滚动的所以你 layout 看起来像这样︰

<?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>
官方微信
官方QQ群
31647020