Android自制ViewPager的TITLE

作者:XINHAO_HAN
根据项目的开发,可能有些东西,框架不能满足你的需求,所以你下载的有些框架改动大,所改的需求量还不如自己写一个

样式图:<标题栏少于等于4个的>

5337239-b347d808624e861b.gif
1513837053156mzfor4.gif

样式图:<标题大于4个的>

5337239-6871bdae545be9b3.gif
1513837372720mzfor4up.gif

思路以及方式

1.主布局

   <RelativeLayout
        android:layout_width="match_parent"
        android:id="@+id/bagRl"
        android:layout_height="wrap_content">

        <!--总体的大布局,这块相当于一个容器-->


    </RelativeLayout>

1.如果标题栏小于等于4个的布局


    <!--这个相当于只添加4个-->


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_marginTop="5dp"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/min_li"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">


        </LinearLayout>


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_marginTop="5dp"
            android:layout_height="wrap_content"
            android:id="@+id/min_rl"
            android:layout_below="@+id/min_li">




        </RelativeLayout>

    </RelativeLayout>

3.标题栏大于等于5个



    <!--这个相当于可以添加无数个-->


    <com.xinhao_han.viewpagerindex.XHHorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/hsv"
        android:scrollbars="none"
        android:layout_marginTop="5dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/max_li"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
               ></LinearLayout>


            <RelativeLayout
                android:id="@+id/max_rl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/max_li"
                android:layout_marginTop="5dp">


            </RelativeLayout>
        </RelativeLayout>


    </com.xinhao_han.viewpagerindex.XHHorizontalScrollView>

在这里你要注意

告诉你一个知识点:

HorizontalScrollView的知识点

如果你要获得HorizontalScrollView的全部宽度公式在这里

//屏幕总宽度
int totleSize = (屏幕宽度+ mHorizontalScrollView.maxScrollAmount) + (左右内边距 * 2) * 总共多少个View;

如果你有N个TextView 并且TextView都设置有边距为P,包括外边距M

那么公式就等于:(屏幕宽度 + mHorizontalScrollView.maxScrollAmount) +(P * 2) +(M * 2) *N

这个玩意mHorizontalScrollView.maxScrollAmount 是你左边总共能滑多少

5337239-430aeb70e92a178d.png
总宽度.png
5337239-da217b3253a6fbf5.png
总宽度.png

HorizontalScrollView的控制滑动方法

mHorizontalScrollView.smoothScrollTo(X, Y);

使用:

mViewPagerTitle.setActivity(this).setViewPager(viewPager).build();

Demo(GitHub): https://github.com/hanxinhao000/viewPagerTitle

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值