使用CollapsingToolbarLayout时Viewpager未出现 [英] Viewpager not appearing when using CollapsingToolbarLayout
问题描述
我一直在玩与周围的设计支持库和所遇到的,我希望有人能帮助我一个小问题。
我使用的含有倒塌parralax一个ImageView的一个CollapsingToolbar。在CollapsingToolbar,我ALSE有这应该是我的滚动一个ViewPager TabLayout。我的问题是,ViewPager不会出现。这个问题似乎只有当我把我的ViewPager layout_height到match_parent或WRAP_CONTENT出现。如果我将其设置为600dp的,那么问题就消失了,但随后的观点最终被一个固定的长度不是很漂亮。
任何帮助将是grealty AP preciated!
下面是我的XML
< android.support.design.widget.CoordinatorLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / main_content
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真正的> < android.support.design.widget.AppBarLayout
机器人:ID =@ + ID / appbar
机器人:layout_width =match_parent
机器人:layout_height =@扪/ detail_backdrop_height
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar
机器人:fitsSystemWindows =真
> < android.support.design.widget.CollapsingToolbarLayout
机器人:ID =@ + ID / collapsing_toolbar
机器人:layout_width =match_parent
机器人:layout_height =match_parent
应用:layout_scrollFlags =滚动| exitUntilCollapsed
机器人:fitsSystemWindows =真
应用:contentScrim =?ATTR / colorPrimary
> < ImageView的
机器人:ID =@ + ID /背景
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
应用:layout_collapseMode =视差
机器人:SRC =@绘制/ stock_image/> < android.support.v7.widget.Toolbar
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
应用:popupTheme =@风格/ ThemeOverlay.AppCompat.Light
机器人:layout_gravity =顶
/> < android.support.design.widget.TabLayout
机器人:ID =@ + ID /标签
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =底/> < /android.support.design.widget.CollapsingToolbarLayout> < /android.support.design.widget.AppBarLayout>
< android.support.v4.widget.NestedScrollView
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
> < android.support.v4.view.ViewPager
机器人:ID =@ + ID / viewpager
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@机器人:彩色/白
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior
/>
< / LinearLayout中>
< /android.support.v4.widget.NestedScrollView>< /android.support.design.widget.CoordinatorLayout>
您应该删除 NestedScrollView
和的LinearLayout
各级之间的 CoordinatorLayout
和 ViewPager
:
< android.support.design.widget.CoordinatorLayout>
< android.support.design.widget.AppBarLayout>
...
< /android.support.design.widget.AppBarLayout> < android.support.v4.view.ViewPager
机器人:ID =@ + ID / viewpager
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@机器人:彩色/白
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>< /android.support.design.widget.CoordinatorLayout>
与应用程序的视图:layout_behavior =@字符串/ appbar_scrolling_view_behavior
必须 CoordinatorLayout
的直接子是关于正确定位的 AppBarLayout
。
I've been playing around with the Design Support Library and have come across a little problem that I hope someone can help me out with.
I'm using a CollapsingToolbar which contain an ImageView which collapses in parralax. In the CollapsingToolbar, I alse have a TabLayout which is supposed to scroll my ViewPager. My issue is that the ViewPager doesn't appear. The issue seems to arise only when I set my ViewPager layout_height to match_parent or wrap_content. If I set it to 600dp, then the problem is gone but then the view ends up being a fixed length which isn't very nice.
Any help would be grealty appreciated!
Here's my 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="@dimen/detail_backdrop_height"
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"
>
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:src="@drawable/stock_image"/>
<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"
android:layout_gravity="top"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
You should remove the NestedScrollView
and LinearLayout
levels between your CoordinatorLayout
and ViewPager
:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
...
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
The view with app:layout_behavior="@string/appbar_scrolling_view_behavior
must be a direct child of CoordinatorLayout
to be positioned correctly in relation to the AppBarLayout
.
这篇关于使用CollapsingToolbarLayout时Viewpager未出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!