相关疑难解决方法(0)

NestedScrollView中的ViewPager

我需要创建一个像Google Newsstand这样的界面,它是一种在折叠标题(垂直滚动)上的ViewPager(水平滚动).我的一个要求是使用Google IO 2015中提供的新设计支持库.(http://android-developers.blogspot.ca/2015/05/android-design-support-library.html)

基于Chris Banes(https://github.com/chrisbanes/cheesesquare)创建的示例,我已经达到了能够执行折叠行为但使用基本LinearLayout(没有水平滚动)的程度.

我试图用ViewPager替换LinearLayout,我得到一个空白屏幕.我玩过:宽度,重量和所有类型的视图组,但....仍然是一个空白的屏幕.似乎ViewPager和NestedScrollView彼此不喜欢.

我通过使用Horizo​​ntalScrollView尝试了一种解决方法:它可以工作,但我放弃了PagerTitleStrip功能的好处,并将焦点放在一个面板上(我可以在两个面板之间水平停​​止).

现在我没有更多的想法,如果有人能引导我找到解决方案......

谢谢

这是我最新的布局文件:

<?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>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-viewpager android-support-library

102
推荐指数
11
解决办法
7万
查看次数

动态高度viewpager

我正在尝试在自定义滚动视图中创建自定义viewpager,动态包装当前子项的高度.

package com.example.vihaan.dynamicviewpager;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.ScrollView;

    /**
     * Created by vihaan on 1/9/15.
     */
    public class CustomScrollView extends ScrollView {

        private GestureDetector mGestureDetector;

        public CustomScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mGestureDetector = new GestureDetector(context, new YScrollDetector());
            setFadingEdgeLength(0);
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return super.onInterceptTouchEvent(ev)
                    && mGestureDetector.onTouchEvent(ev);
        }

        // Return false if we're scrolling in the x direction
        class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2,
                                    float …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-scrollview android-viewpager

28
推荐指数
3
解决办法
2万
查看次数

如何在viewPager的视图顶部使用nestedScrollView中的viewpager

由于viewpager,我无法滚动nestedScrollView.那么让我在这里解释一下我想要创建的布局设计:

enter image description here

NestedScrollView中有FrameLayout,标签布局有viewpager.Viewpager用无尽的recylerview(Pagination)加载三个片段.

这是布局xml代码:

<android.support.design.widget.CoordinatorLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="com.plowns.droidapp.activites.HomeActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/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="wrap_content"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </RelativeLayout>


    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginTop="50dp"
    android:background="@color/colorPrimary" />


<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedscrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@color/trans">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="260dp">

                <android.support.v7.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="55dp"
                    app:cardCornerRadius="5dp">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <ImageView
                            android:id="@+id/txt_edit_icon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/ic_mode_edit"
                            android:tint="@color/blue_plowns" />

                        <TextView
                            android:id="@+id/txt_child_name"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="50dp"
                            android:ellipsize="end"
                            android:gravity="center_vertical"
                            android:minHeight="5dp"
                            android:text="Satwinder Singh"
                            android:textAppearance="?android:attr/textAppearanceListItemSmall"
                            android:textColor="@android:color/black"
                            android:textSize="18sp" …
Run Code Online (Sandbox Code Playgroud)

android android-layout xml-layout android-viewpager android-nestedscrollview

7
推荐指数
1
解决办法
1772
查看次数