• Android-ViewPagerIndicator框架使用——UnderlinePageIndicator


    前言:UnderlinePageIndicator这个指示,是一个很小巧的东西,简单,没有那么多复杂的效果。

        一:布局定义simple_underlines:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            />
        <com.viewpagerindicator.UnderlinePageIndicator
            android:id="@+id/indicator"
            android:layout_height="2dp"
            android:layout_width="fill_parent"
            />
    </LinearLayout>

        二:代码中调用:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.simple_underlines);
    
            mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
    
            mPager = (ViewPager)findViewById(R.id.pager);
            mPager.setAdapter(mAdapter);
    
            mIndicator = (UnderlinePageIndicator)findViewById(R.id.indicator);
            mIndicator.setViewPager(mPager);
        }

        三:可改变的自定义属性:

        <declare-styleable name="UnderlinePageIndicator">
    
            <!-- 指示是否隐藏 -->
            <attr name="fades" format="boolean" />
            <!-- 延迟多久之后隐藏 -->
            <attr name="fadeDelay" format="integer" />
            <!-- 变到全透明的时间 -->
            <attr name="fadeLength" format="integer" />
            <!-- 指示条的颜色 -->
            <attr name="selectedColor" />
            <!-- 控件的背景色 -->
            <attr name="android:background" />
        </declare-styleable>

        四:改变属性的三种方法:

          1.布局中改变:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <com.viewpagerindicator.UnderlinePageIndicator
            android:id="@+id/indicator"
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:background="#FFCCCCCC"
            app:fadeDelay="1000"
            app:fadeLength="1000"
            app:selectedColor="#FFCC0000" />
    
    </LinearLayout>

          3.代码中改变:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.simple_underlines);
    
            mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
    
            mPager = (ViewPager)findViewById(R.id.pager);
            mPager.setAdapter(mAdapter);
    
            UnderlinePageIndicator indicator = (UnderlinePageIndicator)findViewById(R.id.indicator);
            mIndicator = indicator;
            indicator.setViewPager(mPager);
            indicator.setSelectedColor(0xFFCC0000);
            indicator.setBackgroundColor(0xFFCCCCCC);
            indicator.setFadeDelay(1000);
            indicator.setFadeLength(1000);
        }

          3.theme主题定义:

        <style name="StyledIndicators" parent="@android:style/Theme.Light">
            <item name="vpiUnderlinePageIndicatorStyle">@style/CustomUnderlinePageIndicator</item>
        </style>
    
        <style name="CustomUnderlinePageIndicator">
            <item name="selectedColor">#FFCC0000</item>
            <item name="android:background">#FFCCCCCC</item>
            <item name="fadeLength">1000</item>
            <item name="fadeDelay">1000</item>
        </style>

          使用主题:

            <activity
                android:name=".SampleUnderlinesStyledTheme"
                android:label="Underlines/Styled (via theme)"
                android:theme="@style/StyledIndicators" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="com.jakewharton.android.viewpagerindicator.sample.SAMPLE" />
                </intent-filter>
            </activity>

    源码以及Demo下载地址:http://download.csdn.net/detail/as294985925/6796117

  • 相关阅读:
    GCD介绍(二): 多核心的性能
    GCD介绍(一): 基本概念和Dispatch Queue
    iOS 中如何监测某段代码运行的时间
    DSOframer 无法正常加载的解决方案
    Hexo 官方主题 landscape-plus 优化
    在 Parallels Desktop 中,全屏模式使用 Win7,唤醒时黑屏
    VS2015 企业版不支持 JavaScript 语法高亮、智能提醒
    解决 Boot Camp 虚拟机升级到 Windows 10 后 Parallels Desktop 不能识别的问题
    利用SkyDrive Pro 迅速批量下载SharePoint Server 上已上传的文件
    SharePoint Server 2013 让上传文件更精彩
  • 原文地址:https://www.cnblogs.com/qinghuaideren/p/3502214.html
Copyright © 2020-2023  润新知