ViewPager在NestedScrollView [英] ViewPager in a NestedScrollView

查看:1326
本文介绍了ViewPager在NestedScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建立像谷歌报亭的接口,它是在一个倒塌的头(垂直滚动)一种ViewPager(水平滚动)的。我的一个要求是使用psented在谷歌IO 2015年新设计支持库$ P $。 (<一href="http://android-developers.blogspot.ca/2015/05/android-design-support-library.html">http://android-developers.blogspot.ca/2015/05/android-design-support-library.html)

根据克里斯·巴内斯创建的示例( https://github.com/chrisbanes/cheesesquare )我已经到达我是能够做到的折叠行为,但有一个基本的LinearLayout(没有水平滚动)的地步。

我试图通过一个ViewPager更换的LinearLayout,我得到了一个空白屏幕。我打:宽度,重量和所有种类的视图组,但仍....一个空白屏幕。看来,ViewPager和NestedScrollView不喜欢对方。

我尝试了解决方法通过使用Horizo​​ntalScrollView:它的工作原理,但我失去了PagerTitleStrip功能和重点的单一面板上的好处(我可以停止水平之间的2片)

现在我没有更多的想法,如果有人能带我到一个解决方案...

感谢

下面是我最新的布局文件:

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT; android.support.design.widget.CoordinatorLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent&GT;

    &LT; android.support.design.widget.AppBarLayout
        机器人:layout_width =match_parent
        机器人:layout_height =@扪/ header_height
        机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar&GT;

        &LT; android.support.design.widget.CollapsingToolbarLayout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            应用程序:contentScrim =?ATTR / colorPrimary
            应用程序:expandedTitleMarginEnd =64dp
            应用程序:expandedTitleMarginStart =48dp
            应用程序:layout_scrollFlags =滚动| exitUntilCollapsed&GT;

            &LT;包括
                布局=@布局/ part_header
                机器人:layout_width =match_parent
                机器人:layout_height =WRAP_CONTENT
                应用程序:layout_collapseMode =视差/&GT;

            &LT; android.support.v7.widget.Toolbar
                机器人:ID =@ + ID / activity_main_toolbar
                机器人:layout_width =match_parent
                机器人:layout_height =?ATTR / actionBarSize
                应用程序:layout_collapseMode =针
                应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/&GT;

        &LT; /android.support.design.widget.CollapsingToolbarLayout>
    &LT; /android.support.design.widget.AppBarLayout>

    &LT; 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&GT;

        &LT; android.support.v4.view.ViewPager
            机器人:ID =@ + ID / activity_main_viewpager
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:后台=#FFA0/&GT;


    &LT; /android.support.v4.widget.NestedScrollView>
&LT; /android.support.design.widget.CoordinatorLayout>
 

解决方案

好吧,我做了一个小的演示与 ViewPager NestedScrollView 。我所面临的问题是与 ViewPager 的ListView 的高度。因此,我在的ListView ViewPager的高度测量稍加修改。

如果有人想窥视code,这里是链接:<一href="https://github.com/TheLittleNaruto/SupportDesignExample/">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:

这篇关于ViewPager在NestedScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆