android - viewpager 下方的布局未显示在 ScrollView 中

标签 android android-viewpager scrollview

我的目标是将页眉和页脚放到 viewpager(其中 viewpager 有 Recycle、Listviews 等的子 fragment )。当用户向上滚动时,我将 setTranslationY 设置为页眉并将 viewpager 的选项卡粘贴到工具栏。到此一切正常很好,但是当 Listfragment(在 viewpager 内)结束滚动时,页脚布局没有显示。我将所有三个部分(页眉,带 fragment 的 viewpager,页脚)放在 ScrollView 中。

UI 结构类似于 ScrollView(RelativeLayout +ViewPager(4 种不同类型的 fragment )+ RelativeLayout)。 请任何做过类似操作的人分享我如何完成此操作的任何链接。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parent_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">

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

            <android.support.v4.view.ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/view_pager"
                android:text="jfgjfgj" />

            <LinearLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="@dimen/header_height"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/parallax_image_height"
                    android:scaleType="centerCrop"
                    android:src="@drawable/course_ud" />


                <com.pace.bluewinger.activities.demo.slidingTab.SlidingTabLayout
                    android:id="@+id/navig_tab"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/tab_height"
                    android:background="@android:color/white"
                    app:indicatorColor="@color/theme_color"
                    app:shouldExpand="true"
                    app:tabBackgroundP="@layout/sliding_tab_view"
                    app:tabBackgroundTextViewId="@+id/tab_textview" />

            </LinearLayout>
        </RelativeLayout>

    </ScrollView>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar" />

</RelativeLayout>

我正在使用 parallaxheaderviewpager libray用于 viewpager 水平滚动的标题和标签的保留状态。

在我的 Activity 中 -

@Override
    protected void scrollHeader(int scrollY) {

        float translationY = Math.max(-scrollY, mMinHeaderTranslation);
        mHeader.setTranslationY(translationY);
        int baseColor = getResources().getColor(R.color.primary);
        float alpha = Math.min(1, (float) scrollY / mParallaxImageHeight);
        mToolbar.setBackgroundColor(ScrollUtils.getColorWithAlpha(alpha, baseColor));

    }

viewpager 适配器是从 ParallaxFragmentPagerAdapter 扩展而来的,每个 fragment 的布局都具有高度作为 wrap_content。

或者有没有其他方法可以实现上面的UI结构?请帮我完成它。

最佳答案

您不能在 ScrollView 中使用具有动态高度的 ViewPager

改变

android:layout_height="wrap_content"

例如

android:layout_height="1000dp"

它会起作用

关于android - viewpager 下方的布局未显示在 ScrollView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33235267/

相关文章:

android - 以线性布局放置在单选组内后,单选按钮消失

android - 方向更改时找不到 id 的 View IllegalArgumentException :?

android - LinearLayout 和 Webview 在 ScrollVIew 中的大小不一样

安卓.view.InflateException :Error inflating class Button

java - 自定义水平滚动动画来跟踪 Android 中 View 上的手指

android - 我无法设置 TextView layout_height 来包装内容

android - 使用 TabLayout 和 ViewPager 时屏幕下方出现 FloatingActionButton

android - 使用 Sliding tabLayout 在单击选项卡时切换选项卡不起作用

android - ScrollView如何滚动到想要的位置?

ios - 有没有办法将我的 `scrollView` 从我的主类连接或访问到另一个类?