【发布时间】:2015-10-20 11:19:02
【问题描述】:
我的目标是将页眉和页脚放入 viewpager(其中 viewpager 有 Recycle、Listviews 等的子片段)。当用户向上滚动时,我将 setTranslationY 设置为 header 并将 viewpager 的选项卡粘贴到工具栏上。至此一切正常很好,但是当 Listfragment(viewpager 内部)结束滚动时,页脚布局没有显示出来。我将所有三个部分(页眉、带有片段的 viewpager、页脚)都放在滚动视图中。
UI 结构类似于 ScrollView(RelativeLayout +ViewPager(4 种不同类型的片段)+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 来获取标题并保留选项卡的状态以进行视图页面的水平滚动。
在我的活动中-
@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 扩展而来的,每个片段的布局高度为 wrap_content 。
或者有没有其他方法可以实现上述UI结构?请帮我完成它。
【问题讨论】:
-
请向我们展示您的代码..
标签: android android-viewpager scrollview