Fragment滑动切换Bar动画

布局

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!--我的订单-->

    <include layout="@layout/base_title_1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/text_white"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/rl1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <TextView
                android:id="@+id/tv_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginTop="20dp"
                android:text="待支付"
                android:textColor="@color/Theme_color"
                android:textSize="15sp" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <TextView
                android:id="@+id/tv_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginTop="20dp"
                android:text="运送中"
                android:textColor="@color/Text_black"
                android:textSize="15sp" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <TextView
                android:id="@+id/tv_3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginTop="20dp"
                android:text="已完成"
                android:textColor="@color/Text_black"
                android:textSize="15sp" />

          
        </RelativeLayout>

    </LinearLayout>


    <ImageView
        android:id="@+id/id_tab_line_iv"
        android:layout_width="50dp"
        android:layout_height="2.5dp"
        android:layout_centerHorizontal="true"
        android:background="@color/Theme_color"
         />


    <com.lixin.zhongshitongapp.app.view.LazyViewPager
        android:id="@+id/ViewPager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />


</LinearLayout></span>

ViewPager代码

监听

 public class Pagechage implements LazyViewPager.OnPageChangeListener {

        @Override
        public void onPageScrollStateChanged(int arg0) {
            // TODO Auto-generated method stub
            if (arg0 == 2) {
                int i = viewPager.getCurrentItem();
                clean();//清除选中状态
                count(i);//选中监听
            }
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub
            /**
             * arg0 :当前页面,及你点击滑动的页面 arg1:当前页面偏移的百分比
             * arg2:当前页面偏移的像素位置
             */
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) id_tab_line_iv.getLayoutParams();
            if (currentIndex == 0 && arg0 == 0)// 0->1
            {
                lp.leftMargin = (int) (arg1 * (screenWidth * 1.0 / 3) + currentIndex
                        * (screenWidth / 3));

            } else if (currentIndex == 1 && arg0 == 0) // 1->0
            {
                lp.leftMargin = (int) (-(1 - arg1)
                        * (screenWidth * 1.0 / 3) + currentIndex
                        * (screenWidth / 3));
            } else if (currentIndex == 1 && arg0 == 1) // 1->2
            {
                lp.leftMargin = (int) (arg1 * (screenWidth * 1.0 / 3) + currentIndex
                        * (screenWidth / 3));
            } else if (currentIndex == 2 && arg0 == 1) // 2->1
            {
                lp.leftMargin = (int) (-(1 - arg1)
                        * (screenWidth * 1.0 / 3) + currentIndex
                        * (screenWidth / 3));
            }
            id_tab_line_iv.setLayoutParams(lp);

        }

        @Override
        public void onPageSelected(int arg0) {
            // TODO Auto-generated method stub
            currentIndex = arg0;
        }
    }

在onCreate()方法加入

/**
     * 设置滑动条的宽度为屏幕的1/3(根据Tab的个数而定)
     */
    private void initTabLineWidth() {
        DisplayMetrics dpMetrics = new DisplayMetrics();
        getWindow().getWindowManager().getDefaultDisplay().getMetrics(dpMetrics);
        screenWidth = dpMetrics.widthPixels;
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) id_tab_line_iv.getLayoutParams();
        lp.width = screenWidth / 3;
        id_tab_line_iv.setLayoutParams(lp);
    }


 private class Click implements View.OnClickListener {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            clean();
            count(arg0.getId());
        }
    }






  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值