ActionBar的tab栏上左右滑动的横线怎么像微信那样平滑的滑动
ActionBar的tab栏上左右滑动的横线如何像微信那样平滑的滑动
如题,ActionBar上的横线是蹦蹦跳跳的滑动的,如何想微信那样平滑的滑动啊??
------解决方案--------------------
如题,ActionBar上的横线是蹦蹦跳跳的滑动的,如何想微信那样平滑的滑动啊??
------解决方案--------------------
package com.tematch.androidsample;
public class Activity2 extends Activity{
private ViewPager vpager;
public static final int MAX_TAB_SIZE = 3;
public static final String ARGUMENTS_NAME = "args";
public static final String ARG_PLANET_NUMBER = "planet_number";
private LayoutInflater inflater;
private ListView lv;
private ImageView iv;// 页卡标题动画图片
private LinearLayout linearLayout;
private TextView tv1;
private TextView tv2;
private TextView tv3;
private int textViewW = 0;// 页卡标题的宽度
private int currIndex = 0;// 当前页卡编号
private List<View> listviews;
private View view1,view2,view3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
iv = (ImageView) findViewById(R.id.cursor);
linearLayout = (LinearLayout) findViewById(R.id.linearLayout1);
vpager = (ViewPager) this.findViewById(R.id.vpager);
vpager.setOffscreenPageLimit(2);
initview();
initViewPager();
InitTextView();
InitImageView();
}
/* 初始化页卡标题 */
private void InitTextView() {
tv1 = (TextView) findViewById(R.id.text1);
tv2 = (TextView) findViewById(R.id.text2);
tv3 = (TextView) findViewById(R.id.text3);
tv1.setOnClickListener(new MyOnClickListener(0));
tv2.setOnClickListener(new MyOnClickListener(1));
tv3.setOnClickListener(new MyOnClickListener(2));
}
/* 标题点击监听 */
public class MyOnClickListener implements android.view.View.OnClickListener{
private int index = 0;
public MyOnClickListener(int i) {
index = i;
}
@Override
public void onClick(View v) {
vpager.setCurrentItem(index);
}
}
public void initview(){
//监听页面改变的事件
vpager.setOnPageChangeListener(new 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) {
}
});
}
/* 设置标题文本的颜色 */
private void setTextTitleSelectedColor(int arg0) {
int count = vpager.getChildCount();
for (int i = 0; i < count; i++) {
TextView mTextView = (TextView) linearLayout.getChildAt(i);
if (arg0 == i) {
mTextView.setTextColor(0xffc80000);
} else {
mTextView.setTextColor(0xff969696);
}
}
}
/* 设置图片宽度 */
private void setImageViewWidth(int width) {
if (width != iv.getWidth()) {
LayoutParams laParams = (LayoutParams) iv.getLayoutParams();
laParams.width = width;
iv.setLayoutParams(laParams);
}
}
/* 初始化动画 */
private void InitImageView() {
Matrix matrix = new Matrix();
matrix.postTranslate(0, 0);
iv.setImageMatrix(matrix);// 设置动画初始位置
}
/* 初始化ViewPager */
private void initViewPager() {
listviews = new ArrayList<View>();
LayoutInflater mInflater = getLayoutInflater();
/**
* 布局一的界面
*/
view1 = mInflater.inflate(R.layout.fragment_main, null);
/**
* 布局二的界面
*/
view2 = mInflater.inflate(R.layout.fragment_weixin, null);
/**
* 布局三的界面
*/
view3 = mInflater.inflate(R.layout.fragment_weixin, null);