• Android-ViewPagerIndicator框架使用——IconPageIndicator


    前言:IconPageIndicator是将自定义的图片作为指示图标的,这里的图片使用xml实现的。

        1.自己定义图片:

    <?xml version="1.0" encoding="utf-8"?>
    
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_selected="true" android:drawable="@drawable/perm_group_calendar_selected" />
        <item android:drawable="@drawable/perm_group_calendar_normal" />
    </selector>

        2.定义布局文件simple_icons:

    <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.IconPageIndicator
            android:id="@+id/indicator"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

        3:代码中使用布局:

            setContentView(R.layout.simple_icons);
            //这个adapter需要实现IconPagerAdapter中的两个方法
            mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
    
            mPager = (ViewPager) findViewById(R.id.pager);
            mPager.setAdapter(mAdapter);
    
            mIndicator = (IconPageIndicator) findViewById(R.id.indicator);
            mIndicator.setViewPager(mPager);

          其中的mAdapter是实现了IconPagerAdapter中的两个方法:

    public interface IconPagerAdapter {
        /**
         * 获得图片作为指示标识
         */
        int getIconResId(int index);
    
        /**
         * 获得pager个数
         */
        int getCount();
    }

          具体使用如下:

    class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
        protected static final int[] ICONS = new int[] {
                  R.drawable.perm_group_calendar,
                  R.drawable.perm_group_camera,
                  R.drawable.perm_group_device_alarms,
                  R.drawable.perm_group_location
          };
        .......
         @Override
          public int getIconResId(int index) {
            return ICONS[index % ICONS.length];
          }
    }

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

  • 相关阅读:
    php 发送手机验证码
    PHP 发送邮件
    php 图形验证码
    css 把图片变成灰色
    本地配置虚拟主机
    VMware 14 激活密钥
    linux每日命令(12): nl 命令
    linux每日命令(11): cat命令
    linux每日命令(10): touch命令
    linux每日命令(9): cp命令
  • 原文地址:https://www.cnblogs.com/qinghuaideren/p/3501063.html
Copyright © 2020-2023  润新知