Skip to content

Commit

Permalink
完成自定义Navigator的演示
Browse files Browse the repository at this point in the history
  • Loading branch information
hackware1993 committed Sep 13, 2016
1 parent 045b73c commit 68ba983
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_custom_navigator_example"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.lucode.hackware.magicindicatordemo.example.CustomNavigatorExampleActivity">

<TextView
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator1"
android:layout_width="wrap_content"
android:layout_height="@dimen/common_navigator_height"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />

<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator2"
android:layout_width="wrap_content"
android:layout_height="@dimen/common_navigator_height"
android:layout_above="@+id/magic_indicator1"
android:layout_centerHorizontal="true" />

<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="coming soon!" />
android:layout_height="@dimen/common_navigator_height"
android:layout_above="@id/magic_indicator2"
android:layout_centerHorizontal="true" />

</RelativeLayout>

0 comments on commit 68ba983

Please sign in to comment.