From 68ba983d9d3544c6f58e38b6ef6fc5a190286b78 Mon Sep 17 00:00:00 2001 From: hackware1993 Date: Tue, 13 Sep 2016 15:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=87=AA=E5=AE=9A=E4=B9=89Na?= =?UTF-8?q?vigator=E7=9A=84=E6=BC=94=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomNavigatorExampleActivity.java | 68 +++++++++++++++++++ ...tivity_custom_navigator_example_layout.xml | 33 ++++++--- 2 files changed, 92 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/net/lucode/hackware/magicindicatordemo/example/CustomNavigatorExampleActivity.java b/app/src/main/java/net/lucode/hackware/magicindicatordemo/example/CustomNavigatorExampleActivity.java index 0f33cdde..4c8873d1 100644 --- a/app/src/main/java/net/lucode/hackware/magicindicatordemo/example/CustomNavigatorExampleActivity.java +++ b/app/src/main/java/net/lucode/hackware/magicindicatordemo/example/CustomNavigatorExampleActivity.java @@ -1,15 +1,83 @@ package net.lucode.hackware.magicindicatordemo.example; +import android.graphics.Color; import android.os.Bundle; +import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; +import net.lucode.hackware.magicindicator.MagicIndicator; +import net.lucode.hackware.magicindicator.ViewPagerHelper; +import net.lucode.hackware.magicindicator.buildins.circlenavigator.CircleNavigator; import net.lucode.hackware.magicindicatordemo.R; +import net.lucode.hackware.magicindicatordemo.ext.navigator.ScaleCircleNavigator; + +import java.util.Arrays; +import java.util.List; public class CustomNavigatorExampleActivity extends AppCompatActivity { + private static final String[] CHANNELS = new String[]{"CUPCAKE", "DONUT", "ECLAIR", "GINGERBREAD", "HONEYCOMB", "ICE_CREAM_SANDWICH", "JELLY_BEAN", "KITKAT", "LOLLIPOP", "M", "NOUGAT"}; + private List mDataList = Arrays.asList(CHANNELS); + private ExamplePagerAdapter mExamplePagerAdapter = new ExamplePagerAdapter(mDataList); + + private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_navigator_example_layout); + + mViewPager = (ViewPager) findViewById(R.id.view_pager); + mViewPager.setAdapter(mExamplePagerAdapter); + + initMagicIndicator1(); + initMagicIndicator2(); + initMagicIndicator3(); + } + + private void initMagicIndicator1() { + MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1); + CircleNavigator circleNavigator = new CircleNavigator(this); + circleNavigator.setCircleCount(CHANNELS.length); + circleNavigator.setCircleColor(Color.RED); + circleNavigator.setCircleClickListener(new CircleNavigator.OnCircleClickListener() { + @Override + public void onClick(int index) { + mViewPager.setCurrentItem(index); + } + }); + magicIndicator.setNavigator(circleNavigator); + ViewPagerHelper.bind(magicIndicator, mViewPager); + } + + private void initMagicIndicator2() { + MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator2); + CircleNavigator circleNavigator = new CircleNavigator(this); + circleNavigator.setFollowTouch(false); + circleNavigator.setCircleCount(CHANNELS.length); + circleNavigator.setCircleColor(Color.RED); + circleNavigator.setCircleClickListener(new CircleNavigator.OnCircleClickListener() { + @Override + public void onClick(int index) { + mViewPager.setCurrentItem(index); + } + }); + magicIndicator.setNavigator(circleNavigator); + ViewPagerHelper.bind(magicIndicator, mViewPager); + } + + private void initMagicIndicator3() { + MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator3); + ScaleCircleNavigator scaleCircleNavigator = new ScaleCircleNavigator(this); + scaleCircleNavigator.setCircleCount(CHANNELS.length); + scaleCircleNavigator.setNormalCircleColor(Color.LTGRAY); + scaleCircleNavigator.setSelectedCircleColor(Color.DKGRAY); + scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() { + @Override + public void onClick(int index) { + mViewPager.setCurrentItem(index); + } + }); + magicIndicator.setNavigator(scaleCircleNavigator); + ViewPagerHelper.bind(magicIndicator, mViewPager); } } diff --git a/app/src/main/res/layout/activity_custom_navigator_example_layout.xml b/app/src/main/res/layout/activity_custom_navigator_example_layout.xml index f402019b..1954e295 100644 --- a/app/src/main/res/layout/activity_custom_navigator_example_layout.xml +++ b/app/src/main/res/layout/activity_custom_navigator_example_layout.xml @@ -1,19 +1,34 @@ - + + + + + + + android:layout_height="@dimen/common_navigator_height" + android:layout_above="@id/magic_indicator2" + android:layout_centerHorizontal="true" />