我的布局包含一个可折叠的工具栏、一个选项卡和一个视图寻呼机...我将列表视图包装在嵌套滚动视图中,但这无法折叠我的工具栏,我尝试将其替换为 RecyclerView 仍然无法折叠布局无法折叠。我尝试垂直放置许多 20 个按钮,这能够折叠工具栏我已经在github上尝试了几个例子,在stackoverflow上尝试了几个解决方案,但都被证明是徒劳的如果我能够得到解决方案,将不胜感激
<?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/main_content"
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="400dp"
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"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9"
android:src="@drawable/babe" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="#ffffff"
app:tabTextColor="#03A9F4"
app:layout_collapseMode="pin"
app:tabSelectedTextColor="#0288D1"
app:tabContentStart="72dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@null"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Fragment_one列表视图
<android.support.v4.widget.NestedScrollView
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true" >
<ListView
android:id="@+id/profilestatus_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@null"
android:divider="#03A9F4"
android:dividerHeight="1dp" />
</android.support.v4.widget.NestedScrollView>
Fragment_two与Recycler_View
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="500dp"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"/>
</android.support.v4.widget.NestedScrollView>
Dummy_Fragment包含按钮,它能够折叠工具栏
<android.support.v4.widget.NestedScrollView
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YO YO"
/>
</ListView>
</android.support.v4.widget.NestedScrollView>
所有的帮助将不胜感激...谢谢
你不需要NestedScrollView
只需删除它,一切就会正常。
UPD_0:
同时尝试将ViewPagers
高度设置为 match_parent
android:layout_height="match_parent"
UPD_1:
还尝试将app:layout_scrollFlags="scroll|enterAlways"
添加到TabLayout
和ImageView
中,这些CollapsingToolbarLayout
。
还要确保使用最新版本的design
、suport-v7
和recycler-view
库。
这是一个可行的解决方案
activity_main.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/main_content"
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="400dp"
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"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9"
app:layout_scrollFlags="scroll|enterAlways"
android:src="@drawable/babe" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="#ffffff"
app:tabTextColor="#03A9F4"
app:tabSelectedTextColor="#0288D1"
app:tabContentStart="72dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@null"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>
</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>
然后对于片段,按照@mohax的建议删除下一个滚动视图
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"/>