use of android.support.v4.view.ViewPager.OnPageChangeListener in project SmartMesh_Android by SmartMeshFoundation.
the class ScanLargePic method setListener.
@Override
protected void setListener() {
deleteTV.setOnClickListener(new MyDeleteListener());
vpPhotos.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
currentSelected = arg0 + 1;
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
if (titleBar.getVisibility() == View.VISIBLE) {
TranslateAnimation gone = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1);
gone.setDuration(300);
gone.setFillAfter(true);
titleBar.setAnimation(gone);
titleBar.setVisibility(View.GONE);
}
}
});
}
use of android.support.v4.view.ViewPager.OnPageChangeListener in project JustAndroid by chinaltz.
the class AbPlayView method initView.
/**
* 初始化这个View.
* @param context the context
*/
public void initView(Context context) {
this.context = context;
navLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
this.setOrientation(LinearLayout.VERTICAL);
RelativeLayout mRelativeLayout = new RelativeLayout(context);
mViewPager = new AbInnerViewPager(context);
// 手动创建的ViewPager,如果用fragment必须调用setId()方法设置一个id
mViewPager.setId(R.id.view_pager);
// 导航的点
mNavLayoutParent = new LinearLayout(context);
mNavLayoutParent.setPadding(0, 5, 0, 5);
navLinearLayout = new LinearLayout(context);
navLinearLayout.setPadding(15, 1, 15, 1);
navLinearLayout.setVisibility(View.INVISIBLE);
mNavLayoutParent.addView(navLinearLayout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
lp1.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
mRelativeLayout.addView(mViewPager, lp1);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
mRelativeLayout.addView(mNavLayoutParent, lp2);
addView(mRelativeLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mViewList = new ArrayList<View>();
mViewPagerAdapter = new AbViewPagerAdapter(context, mViewList);
mViewPager.setAdapter(mViewPagerAdapter);
mViewPager.setFadingEdgeLength(0);
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
makesurePosition();
onPageSelectedCallBack(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
onPageScrolledCallBack(position);
}
});
}
use of android.support.v4.view.ViewPager.OnPageChangeListener in project FishChatAndroid by oikomi.
the class ChatMainActivity method initView.
private void initView() {
mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
mChatTextView = (TextView) findViewById(R.id.id_tv_chat);
mFriendTextView = (TextView) findViewById(R.id.id_tv_friend);
mContactTextView = (TextView) findViewById(R.id.id_tv_contact);
mMeTextView = (TextView) findViewById(R.id.id_tv_me);
mChatLinearLayout = (LinearLayout) findViewById(R.id.id_ll_chat);
mDatas = new ArrayList<Fragment>();
mDatas.add(tab01);
mDatas.add(tab02);
mDatas.add(tab03);
mDatas.add(tab04);
mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
return mDatas.size();
}
@Override
public Fragment getItem(int arg0) {
return mDatas.get(arg0);
}
};
mViewPager.setAdapter(mAdapter);
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
resetTextView();
switch(position) {
case 0:
if (mBadgeView != null) {
mChatLinearLayout.removeView(mBadgeView);
}
mBadgeView = new BadgeView(ChatMainActivity.this);
mBadgeView.setBadgeCount(7);
mChatLinearLayout.addView(mBadgeView);
mChatTextView.setTextColor(Color.parseColor("#008000"));
break;
case 1:
mContactTextView.setTextColor(Color.parseColor("#008000"));
break;
case 2:
mFriendTextView.setTextColor(Color.parseColor("#008000"));
break;
case 3:
mMeTextView.setTextColor(Color.parseColor("#008000"));
break;
}
mCurrentPageIndex = position;
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPx) {
Log.e("TAG", position + " , " + positionOffset + " , " + positionOffsetPx);
LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) mTabline.getLayoutParams();
if (// 0->1
mCurrentPageIndex == 0 && position == 0) {
lp.leftMargin = (int) (positionOffset * mScreen1_4 + mCurrentPageIndex * mScreen1_4);
} else if (// 1->0
mCurrentPageIndex == 1 && position == 0) {
lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset - 1) * mScreen1_4);
} else if (// 1->2
mCurrentPageIndex == 1 && position == 1) {
lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + positionOffset * mScreen1_4);
} else if (// 2->1
mCurrentPageIndex == 2 && position == 1) {
lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset - 1) * mScreen1_4);
} else if (// 2->3
mCurrentPageIndex == 2 && position == 2) {
lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset) * mScreen1_4);
} else if (// 3->2
mCurrentPageIndex == 3 && position == 1) {
lp.leftMargin = (int) (mCurrentPageIndex * mScreen1_4 + (positionOffset - 1) * mScreen1_4);
}
mTabline.setLayoutParams(lp);
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
use of android.support.v4.view.ViewPager.OnPageChangeListener in project iosched by google.
the class TabLayout method setupWithViewPager.
private void setupWithViewPager(@Nullable final ViewPager viewPager, boolean autoRefresh, boolean implicitSetup) {
if (mViewPager != null) {
// If we've already been setup with a ViewPager, remove us from it
if (mPageChangeListener != null) {
mViewPager.removeOnPageChangeListener(mPageChangeListener);
}
if (mAdapterChangeListener != null) {
mViewPager.removeOnAdapterChangeListener(mAdapterChangeListener);
}
}
if (mCurrentVpSelectedListener != null) {
// If we already have a tab selected listener for the ViewPager, remove it
removeOnTabSelectedListener(mCurrentVpSelectedListener);
mCurrentVpSelectedListener = null;
}
if (viewPager != null) {
mViewPager = viewPager;
// Add our custom OnPageChangeListener to the ViewPager
if (mPageChangeListener == null) {
mPageChangeListener = new TabLayoutOnPageChangeListener(this);
}
mPageChangeListener.reset();
viewPager.addOnPageChangeListener(mPageChangeListener);
// Now we'll add a tab selected listener to set ViewPager's current item
mCurrentVpSelectedListener = new ViewPagerOnTabSelectedListener(viewPager);
addOnTabSelectedListener(mCurrentVpSelectedListener);
final PagerAdapter adapter = viewPager.getAdapter();
if (adapter != null) {
// Now we'll populate ourselves from the pager adapter, adding an observer if
// autoRefresh is enabled
setPagerAdapter(adapter, autoRefresh);
}
// Add a listener so that we're notified of any adapter changes
if (mAdapterChangeListener == null) {
mAdapterChangeListener = new AdapterChangeListener();
}
mAdapterChangeListener.setAutoRefresh(autoRefresh);
viewPager.addOnAdapterChangeListener(mAdapterChangeListener);
// Now update the scroll position to match the ViewPager's current item
setScrollPosition(viewPager.getCurrentItem(), 0f, true);
} else {
// We've been given a null ViewPager so we need to clear out the internal state,
// listeners and observers
mViewPager = null;
setPagerAdapter(null, false);
}
mSetupViewPagerImplicitly = implicitSetup;
}
Aggregations