美文网首页
Android自制ViewPager的TITLE

Android自制ViewPager的TITLE

作者: XINHAO_HAN | 来源:发表于2017-12-21 14:57 被阅读0次

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

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

1513837053156mzfor4.gif

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

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 是你左边总共能滑多少

总宽度.png 总宽度.png

HorizontalScrollView的控制滑动方法

mHorizontalScrollView.smoothScrollTo(X, Y);

使用:

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

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

相关文章

网友评论

      本文标题:Android自制ViewPager的TITLE

      本文链接:https://www.haomeiwen.com/subject/vuhawxtx.html