当前位置:我的异常网» Android » ActionBar的tab栏上左右滑动的横线怎么像微信那样平
ActionBar的tab栏上左右滑动的横线怎么像微信那样平滑的滑动(2)
www.myexceptions.net 网友分享于:2014-04-07 浏览:429次
listviews.add(view1);
listviews.add(view2);
listviews.add(view3);
vpager.setAdapter(new MyPagerAdapter(listviews));
vpager.setCurrentItem(0);
vpager.setOnPageChangeListener(new MyOnPageChangeListener());
}
/**
* ViewPager适配器
*/
public class MyPagerAdapter extends PagerAdapter {
public List mListViews;
public MyPagerAdapter(List mListViews) {
this.mListViews = mListViews;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView(mListViews.get(arg1));
}
@Override
public void finishUpdate(View arg0) {
}
@Override
public int getCount() {
return mListViews.size();
}
@Override
public Object instantiateItem(View arg0, int arg1) {
((ViewPager) arg0).addView(mListViews.get(arg1), 0);
return mListViews.get(arg1);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == (arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
}
/* 页卡切换监听 */
public class MyOnPageChangeListener implements OnPageChangeListener {
@Override
public void onPageSelected(int arg0) {
if (textViewW == 0) {
textViewW = tv1.getWidth();
}
Animation animation = new TranslateAnimation(textViewW * currIndex,
textViewW * arg0, 0, 0);
currIndex = arg0;
animation.setFillAfter(true);/* True:图片停在动画结束位置 */
animation.setDuration(300);
iv.startAnimation(animation);
setTextTitleSelectedColor(arg0);
setImageViewWidth(textViewW);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
}
/**
* 返回上一界面
*/
public void back(View v){
finish();
}
}
}
xml文件
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
style="@android:style/Theme.Holo.Light"
>
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center" >
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="刷卡消费"
android:textColor="#969696"
android:textSize="17dp" />
android:id="@+id/text2"
android:layout_width="0dp"
文章评论