我想实现viewpager上方的文本淡出然后当用户滚动到不同的页面时淡出。我在工具栏中有一个TextView,并根据页面设置文本。我使用的是TextView而不是工具栏标题,因为我相信实现动画会更容易。我如何设置textview的动画以使其当前文本淡出然后淡入下一页文本?如果您需要更多代码或问题有任何问题,我会更新我的答案。
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:geekui="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="56dp"
android:layout_width="match_parent"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/primary">
<com.mobsandgeeks.ui.TypefaceTextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="@color/white"
android:gravity="center_vertical"
android:text="Testing"
geekui:customTypeface="fonts/Roboto-Regular.ttf" />
</android.support.v7.widget.Toolbar>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
活动
private Toolbar toolbar;
private void toolbarFunction() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
tvTitle.setText(dbTwoName);
}
private ViewPager mViewPager;
private void viewPagerConnections() {
tvTitle = (TextView) findViewById(R.id.tvTitle);
mViewPager = (ViewPager) findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager();
mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) {
@Override
public Fragment getItem(int position) {
LogSecond log = logSecondAdapter.getItem(position);
return LogThirdFragment.newInstance(log.getDB_twoName(), position, log.getDB_twoKey());
}
@Override
public int getCount() {
return logSecondAdapter.getCount();
}
});
mViewPager.setCurrentItem(currentPageInt);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
LogSecond logSecond = logSecondAdapter.getItem(position);
tvTitle.setText(logSecond.getDB_twoName());
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}