75行のミニマムなViewPagerIndicatorライブラリ書いた
特徴
- コードベースがかなり小さい
- シンプルなインターフェース
使い方
参照するレポジトリにjitpackを追加して、
repositories {
maven {
url "https://jitpack.io"
}
}
LxIndicatorViewをdependenciesに追加する
dependencies {
compile 'com.github.kazy1991:LxIndicatorView:0.2'
}
下のコードがサンプルの実装
public class RootActivity extends AppCompatActivity { private final static int[] COLOR_LIST = {0xff7cd5aa, 0xfff1e6a2, 0xfffecc5a, 0xffff8b58, 0xffe92440}; private final static int VIEW_COUNT = COLOR_LIST.length; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_root); final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager); final LxIndicatorGroup indicatorGroup = (LxIndicatorGroup) findViewById(R.id.indicator_view); indicatorGroup.setup(VIEW_COUNT, R.drawable.indicator); SampleViewPagerAdapter adapter = new SampleViewPagerAdapter(); for (int color : COLOR_LIST) { FrameLayout view = new FrameLayout(this); view.setBackgroundColor(color); adapter.addView(view); } viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(indicatorGroup.getSyncPositionListener()); } }
詳細はレポジトリのサンプルを参照
背景
IndicatorViewが欲しくなって書いたんですが、今まで4~5回は実装を書いてるので分離してライブラリにしました。
凝ったアニメーションはいらないけど、自分で実装するのはダルい という時お使いください。