前言:LinePageIndicator类似CirclePageIndicator,只是将圆点指示变成了长条指示。

    一:使用是定义的布局文件simple_lines  :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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.LinePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip" />
</LinearLayout>

    二:代码中使用:

        setContentView(R.layout.simple_lines);

        mAdapter = new TestFragmentAdapter(getSupportFragmentManager());

        ViewPager mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter); LinePageIndicator mIndicator = (LinePageIndicator) findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);

    三:修改属该改变样式,下边可以修改的属性值:

<declare-styleable name="LinePageIndicator">

        <!-- 是否居中显示 -->
<attr name="centered" />
<!-- 没有被选择标识的颜色 -->
<attr name="unselectedColor" />
<!-- 被选择标识的颜色 -->
<attr name="selectedColor" />
<!-- 标识的宽度大小 -->
<attr name="lineWidth" format="dimension" />
<!-- 标识的高度 -->
<attr name="strokeWidth" />
<!-- 标识间隔大小 -->
<attr name="gapWidth" format="dimension" />
<!-- 整体的背景色 -->
<attr name="android:background" />
</declare-styleable>

      1.代码修改样式:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_lines); mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter); LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.indicator);
mIndicator = indicator;
indicator.setViewPager(mPager);
// 获得屏幕的密度
final float density = getResources().getDisplayMetrics().density;
indicator.setSelectedColor(0x88FF0000);
indicator.setUnselectedColor(0xFF888888);
indicator.setStrokeWidth(4 * density);
indicator.setLineWidth(30 * density);
}

      2.布局中修改:

<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.LinePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
app:lineWidth="30dp"
app:selectedColor="#FF880000"
app:strokeWidth="4dp"
app:unselectedColor="#FF888888" />
</LinearLayout>

      3.主题方式修改:

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

      主题:

    <style name="CustomLinePageIndicator" parent="@android:style/Theme.Light">
<item name="strokeWidth">4dp</item>
<item name="lineWidth">30dp</item>
<item name="unselectedColor">#FF888888</item>
<item name="selectedColor">#FF880000</item>
</style>

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

最新文章

  1. MVC中Action参数绑定的过程
  2. P4行为模型BMV2依赖关系安装:thrift nanomsg nnpy安装
  3. 剑指Offer:面试题5——从尾到头打印链表(java实现)
  4. jquery.flip插件翻转效果
  5. 使用CKEditor编辑器进行文本编辑
  6. Sublime Text各种插件使用方法
  7. 在ubuntu14.04上部署hadoop2.6.3
  8. JavaScript 中的正常任务与微任务
  9. 基于Apache搭建Nagios图形监控
  10. Servlet过滤器简单探索
  11. MongoDB分组
  12. numpy科学计算库的基础用法,完美抽象多维数组(原创)
  13. Linux suse 11 sp1 安装教程
  14. 补发————grid布局
  15. [luogu1970][花匠]
  16. 涂抹mysql笔记-mysql管理工具
  17. Linux权限赋予远程连接MySQL
  18. NoSQL&amp;Redis
  19. xshell连接不上linux情况一
  20. free的说明

热门文章

  1. 一、ELKStack介绍与入门实践
  2. ARP协议具体解释之ARP动态与静态条目的生命周期
  3. 协程基础_context系列函数
  4. 用.net installshield打包程序时注册第三方控件
  5. Ant 风格路径表达式(转)
  6. Java常见分页方式
  7. Smooks转换设计
  8. 插入数据返回插入的主键Id
  9. Android apktool反编译资源文件为空解决办法(测试天猫、淘宝等apk成功)
  10. tcp/ip ---数据封装过程