【发布时间】:2016-09-15 23:15:17
【问题描述】:
我在顶部有一个FrameLayout
ViewPager 在底部 FrameLayout 有 PagerTabStrips ViewPager 有 ScrollView 在里面。
我想要实现的是,在 ViewPager 的 ScrollView 的滚动上,我想平滑地同步平移 ViewPager 和 FrameLayout 的 Y 位置。
在某些时候,我必须修复 FrameLayout 的位置并停止其进一步滚动到顶部。
以下是我的 xml 代码:
<?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/com.example"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/parentRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:clickable="true"
android:clipToPadding="false"
android:fitsSystemWindows="true" >
<FrameLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.sticky.pager.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:layout_gravity="bottom"
android:layout_marginTop="2dp" />
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header"
android:background="@color/blue" />
</RelativeLayout>
如何以编程方式实现这一点:
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount, int pagePosition) {
float scrollY=getScrollY(view);
mViewPager.setTranslationY(-scrollY);
mHeader.setTranslationY(-scrollY);
//What to write here??? This does not work
【问题讨论】:
标签: android animation scrollview translate