我需要建立像谷歌报亭的接口,它是在一个倒塌的头(垂直滚动)一种ViewPager(水平滚动)的。我的一个要求是使用psented在谷歌IO 2015年新设计支持库$ P $。 (http://android-developers.blogspot.ca/2015/05/android-design-support-library.html)
根据克里斯·巴内斯创建的示例( https://github.com/chrisbanes/cheesesquare )我已经到达我是能够做到的折叠行为,但有一个基本的LinearLayout(没有水平滚动)的地步。
我试图通过一个ViewPager更换的LinearLayout,我得到了一个空白屏幕。我打:宽度,重量和所有种类的视图组,但仍....一个空白屏幕。看来,ViewPager和NestedScrollView不喜欢对方。
我尝试了解决方法通过使用HorizontalScrollView:它的工作原理,但我失去了PagerTitleStrip功能和重点的单一面板上的好处(我可以停止水平之间的2片)
现在我没有更多的想法,如果有人能带我到一个解决方案...
感谢
下面是我最新的布局文件:
< XML版本=1.0编码=UTF-8&GT?;
< android.support.design.widget.CoordinatorLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
< android.support.design.widget.AppBarLayout
机器人:layout_width =match_parent
机器人:layout_height =@扪/ header_height
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar>
< android.support.design.widget.CollapsingToolbarLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
应用程序:contentScrim =?ATTR / colorPrimary
应用程序:expandedTitleMarginEnd =64dp
应用程序:expandedTitleMarginStart =48dp
应用程序:layout_scrollFlags =滚动| exitUntilCollapsed>
<包括
布局=@布局/ part_header
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
应用程序:layout_collapseMode =视差/>
< android.support.v7.widget.Toolbar
机器人:ID =@ + ID / activity_main_toolbar
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
应用程序:layout_collapseMode =针
应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>
< /android.support.design.widget.CollapsingToolbarLayout>
< /android.support.design.widget.AppBarLayout>
< android.support.v4.widget.NestedScrollView
机器人:ID =@ + ID / activity_main_nestedscrollview
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fillViewport =真
应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior>
< android.support.v4.view.ViewPager
机器人:ID =@ + ID / activity_main_viewpager
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:后台=#FFA0/>
< /android.support.v4.widget.NestedScrollView>
< /android.support.design.widget.CoordinatorLayout>
解决方案
好吧,我做了一个小的演示与 ViewPager
和 NestedScrollView
。我所面临的问题是与 ViewPager
和的ListView
的高度。因此,我在的ListView
和 ViewPager的
高度测量稍加修改。
如果有人想窥视code,这里是链接:https://github.com/TheLittleNaruto/SupportDesignExample/
输出:
I need to create an interface like Google Newsstand which is a sort of ViewPager (horizontal scroll) over a collapsing header (vertical scroll). One of my requirements is to use the new Design Support Library presented at the Google IO 2015. (http://android-developers.blogspot.ca/2015/05/android-design-support-library.html)
Based on the sample created by Chris Banes (https://github.com/chrisbanes/cheesesquare) I've reach the point that I'm able to do the collapsing behaviour but with a basic LinearLayout (without horizontal scroll).
I tried to replace the LinearLayout by a ViewPager and I got a blank screen. I played with: width, weight and all kind of view groups but.... still a blank screen. It seems that ViewPager and NestedScrollView don't like each other.
I tried a workaround by using an HorizontalScrollView: it works but I loose the benefit of the PagerTitleStrip feature and the focus on a single panel (I can stop the horizontally between 2 panels).
Now I have no more ideas, if anyone can lead me to a solution...
Thanks
Here is my latest layout file :
<?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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
layout="@layout/part_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/activity_main_nestedscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="@+id/activity_main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFA0"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
解决方案
Okay, I made a small demo with the ViewPager
and NestedScrollView
. The problem I faced was with the height of ViewPager
and the ListView
. So I did a little modification on ListView
and ViewPager's
height measuring.
If anyone would like to look into the code, Here is the link: https://github.com/TheLittleNaruto/SupportDesignExample/
Output:
相关推荐
最新文章