Android自制ViewPager的TITLE

作者: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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,815评论 1 92
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,663评论 25 708
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,810评论 0 2
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,571评论 0 17
  • 最近通过练习拳击,意识到一些学习态度及方法的问题。 拳击练习,首先是对基本原理的了解,然后是不断的练习...
    呼呼海爸阅读 256评论 0 1