Skip to content

Commit

Permalink
type=bazier control points init
Browse files Browse the repository at this point in the history
readme
  • Loading branch information
LinweiJ committed Sep 8, 2017
1 parent 340ae02 commit e64c362
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 29 deletions.
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
# ViewPagerIndicator
## ViewPagerIndicator

一个简单好用的ViewPagerIndicator,提供了五种类型,采用在XML布局中定制颜色大小等参数,在JAVA代码中只需二行代码就能为viewpager添加酷炫效果,并且支持轮播图。

[![](https://jitpack.io/v/LinweiJ/ViewPagerIndicator.svg)](https://jitpack.io/#LinweiJ/ViewPagerIndicator)

![ViewPagerIndicator.gif](https://github.com/LinweiJ/ViewPagerIndicator/blob/master/screen_shot/ViewPagerIndicator.gif)

## 文档

- [English](https://github.com/LinweiJ/ViewPagerIndicator/blob/master/README_EN.md)
- [中文](https://github.com/LinweiJ/ViewPagerIndicator/blob/master/README.md)



## 如何使用它?

### 先在 project的build.gradle 添加:

```
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```

### 然后在module的build.gradle 添加:

```
dependencies {
compile 'com.github.LinweiJ:ViewPagerIndicator:0.0.2'
}
```

## 使用

1. 将ViewPagerIndicator 添加到xml

```
<com.lwj.widget.viewpagerindicator.ViewPagerIndicator
android:id="@+id/indicator_line"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#efefef"
app:default_color="#cdcdcd"
app:distance="800dp"
app:distanceType="BY_LAYOUT"
app:indicatorType="LINE"
app:length="24dp"
app:radius="8dp"
app:selected_color="#FF23EEF5"
/>
```

Properties:

- `app:selected_color`
- `app:default_color` (如果 indicatorType=CIRCLE_LINE default_color 为指示器唯一颜色 ,selected_color 不起作用)
- `app:radius` (点的大小,在indicatorType= CIRCLE_LINE 的情况下 radius 是点的高)
- `app:length` (只作用在 indicatorType=CIRCLE_LINE 的情况下,为 指示器点的长度)
- `app:distance` (只作用在 distanceType=BY_DISTANCE 的情况下)
- `app:num`
- `app:indicatorType` (LINE; CIRCLE; CIRCLE_LINE; BEZIER;SPRING)

​ LINE:线 ; CIRCLE:圆点(默认) ; CIRCLE_LINE:圆角矩形; BEZIER:弹性球 ; SPRING: 弹簧粘性球

- `app:distanceType` (BY_RADIUS; BY_DISTANCE ; BY_LAYOUT )

​ BY_RADIUS:3倍radius ; BY_DISTANCE :定义固定距离 ;BY_LAYOUT :根据layout_width均分得到距离

1. java

```java
mViewPagerIndicator = (ViewPagerIndicator) findViewById(R.id.viewPagerIndicator);

//viewpager是固定页数, 传入viewpager即可
mViewPagerIndicator.setViewPager(mViewpager);

//viewpager是轮播图 ,如:总数为100000个 实际展示页为6个
//需要传入实际展示个数num
mViewPagerIndicator.setViewPager(mViewpager,num);

```

3.更多

可以参考 demo/ 示例

## License

```
Copyright 2017 LinWeiJia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
## 底部

随手给颗星呗 ? (>_@)
106 changes: 105 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
@@ -1 +1,105 @@
# ViewPagerIndicator
## ViewPagerIndicator

A simple, cool, customizable ViewPagerIndicator,provides five indicator type,custom color,size,type... in layout XML ,in JAVA code just two lines of code to show cool indicator for viewpager , it also good for viewpager as carousel .

[![](https://jitpack.io/v/LinweiJ/ViewPagerIndicator.svg)](https://jitpack.io/#LinweiJ/ViewPagerIndicator)

![ViewPagerIndicator.gif](https://github.com/LinweiJ/ViewPagerIndicator/blob/master/screen_shot/ViewPagerIndicator.gif)

## Document

- [English](https://github.com/LinweiJ/ViewPagerIndicator/blob/master/README_EN.md)
- [中文](https://github.com/LinweiJ/ViewPagerIndicator/blob/master/README.md)

## Gradle

Add it in your root build.gradle at the end of repositories:

```
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```

Add the dependency in your module build.gradle :

```
dependencies {
compile 'com.github.LinweiJ:ViewPagerIndicator:0.0.1'
}
```



## Usage

1.add **ViewPagerIndicator** to your layout xml

```
<com.lwj.widget.viewpagerindicator.ViewPagerIndicator
android:id="@+id/indicator_line"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#efefef"
app:default_color="#cdcdcd"
app:distance="800dp"
app:distanceType="BY_LAYOUT"
app:indicatorType="LINE"
app:length="24dp"
app:radius="8dp"
app:selected_color="#FF23EEF5"
/>
```

Properties:

- `app:selected_color`
- `app:default_color` (if CIRCLE_LINE(indicatorType) default_color is indicator color ,selected_color not work)
- `app:radius` (if CIRCLE_LINE(indicatorType) radius is indicator height)
- `app:length` (work with CIRCLE_LINE(indicatorType))
- `app:distance` (work with BY_DISTANCE (distanceType))
- `app:num`
- `app:indicatorType` (LINE; CIRCLE; CIRCLE_LINE; BEZIER ;SPRING)
- `app:distanceType` (BY_RADIUS ; BY_DISTANCE ; BY_LAYOUT )

2.find **ViewPagerIndicator** through code, work with ViewPager

```java
mViewPagerIndicator = (ViewPagerIndicator) findViewById(R.id.viewPagerIndicator);

//if viewpager's pages is limited , exact, fixed , not carousel
mViewPagerIndicator.setViewPager(mViewpager);

//if viewpager's carousel , ex: allNum=100000 realNum=6
//you must give num = realNum ,ViewPagerIndicator need it to work
mViewPagerIndicator.setViewPager(mViewpager,num);
```

3.more usage

*For a working implementation of this project see the app/ folder.*

## License

```
Copyright 2017 LinWeiJia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

## More

Why not give a star ? (>_@)
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="弹性粘性球(spring)"/>
android:text="弹簧粘性球(spring)"/>
<com.lwj.widget.viewpagerindicator.ViewPagerIndicator
android:id="@+id/indicator_spring"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/activity_not_carousel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="弹性粘性球(spring)"/>
android:text="弹簧粘性球(spring)"/>
<com.lwj.widget.viewpagerindicator.ViewPagerIndicator
android:id="@+id/indicator_spring"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ private void changePoint() {
float mc = M;
mControlPoint[2].y = mRadius;//底部
mControlPoint[8].y = -mRadius;//顶部
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius;//左半圆

//圆心位置
if (mPosition == mNum - 1 && !mIsLeft) {//第一个 右滑 0-->4
Expand All @@ -332,9 +330,7 @@ private void changePoint() {
mCenterPoint.x = -(mNum - 1) * 0.5f * mDistance;
}
//控制点位置
if (mPercent >= 1) {//圆

} else if (mPercent > 0.8 && mPercent <= 1) {//右凸起 圆心不变
if (mPercent > 0.8 && mPercent <= 1) {//右凸起 圆心不变
mControlPoint[5].x = mCenterPoint.x + mRadius * (2 - (mPercent - 0.8f) / 0.2f);//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius;//左半圆
} else if (mPercent > 0.5 && mPercent <= 0.8) {//加速 左凸起 扁平化M 最右端固定不变 圆心移动
Expand All @@ -352,11 +348,9 @@ private void changePoint() {
} else if (mPercent > 0.1 && mPercent <= 0.2) {//左凹 圆心到达.0
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius * (1 - (0.2f - mPercent) / 0.1f * 0.5f);//左半圆
} else if (mPercent > 0 && mPercent <= 0.1) {//回弹 圆心到达
} else if (mPercent >= 0 && mPercent <= 0.1) {//回弹 圆心到达
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius * (1 - (mPercent) / 0.1f * 0.5f);//左半圆
} else if (mPercent == 0) {//圆

}

} else if (mPosition == mNum - 1 && mIsLeft) {//最后一个 左滑 4-->0
Expand All @@ -372,7 +366,7 @@ private void changePoint() {

if (mPercent <= 0) {//圆

} else if (mPercent <= 0.2 && mPercent > 0) {//左凸起 圆心不变
} else if (mPercent <= 0.2 && mPercent >= 0) {//左凸起 圆心不变
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius * (1 + (mPercent) / 0.2f);//左半圆
} else if (mPercent > 0.2 && mPercent <= 0.5) {//加速 右凸起 扁平化M 最左端固定不变 圆心移动
Expand All @@ -393,9 +387,9 @@ private void changePoint() {
} else if (mPercent > 0.9 && mPercent <= 1) {//回弹 圆心到达
mControlPoint[5].x = mCenterPoint.x + mRadius * (1 - (mPercent - 0.9f) / 0.1f * 0.5f);//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius;//左半圆
} else if (mPercent == 1) {//圆

}


} else {
if (mPercent <= 0.2) {//圆
mCenterPoint.x = -(mNum - 1) * 0.5f * mDistance + mPosition * mDistance;
Expand All @@ -410,9 +404,7 @@ private void changePoint() {
//控制点位置
if (mIsLeft)//左滑
{
if (mPercent <= 0) {//圆

} else if (mPercent > 0 && mPercent <= 0.2) {//右凸起 圆心不变
if (mPercent >= 0 && mPercent <= 0.2) {//右凸起 圆心不变
mControlPoint[5].x = mCenterPoint.x + mRadius * (2 - (0.2f - mPercent) / 0.2f);//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius;//左半圆
} else if (mPercent > 0.2 && mPercent <= 0.5) {//加速 左凸起 扁平化M 最右端固定不变 圆心移动
Expand All @@ -427,20 +419,16 @@ private void changePoint() {
mControlPoint[2].y = mRadius * (1 + (mPercent - 0.8f) / 0.3f * 0.1f);//底部
mControlPoint[8].y = -mRadius * (1 + (mPercent - 0.8f) / 0.3f * 0.1f);//顶部
mc = mc * (1 + (-mPercent + 0.8f) / 0.3f * 0.3f);
} else if (mPercent > 0.8 && mPercent < 0.9) {//左凹 圆心到达
} else if (mPercent > 0.8 && mPercent <= 0.9) {//左凹 圆心到达
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius * (1 - (mPercent - 0.8f) / 0.1f * 0.5f);//左半圆
} else if (mPercent > 0.9 && mPercent < 1) {//回弹 圆心到达
} else if (mPercent > 0.9 && mPercent <= 1) {//回弹 圆心到达
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius * (1 - (1.0f - mPercent) / 0.1f * 0.5f);//左半圆
} else if (mPercent == 1) {//圆

}
} else//左滑
} else//右滑
{
if (mPercent >= 1) {//圆

} else if (mPercent < 1 && mPercent >= 0.8) {//左凸起 圆心不变
if (mPercent <= 1 && mPercent >= 0.8) {//左凸起 圆心不变
mControlPoint[5].x = mCenterPoint.x + mRadius;//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius * (2 - (mPercent - 0.8f) / 0.2f);//左半圆
} else if (mPercent > 0.5 && mPercent <= 0.8) {//加速 右凸起 扁平化M 最左端固定不变 圆心移动
Expand All @@ -458,12 +446,11 @@ private void changePoint() {
} else if (mPercent > 0.1 && mPercent <= 0.2) {//右凹 圆心到达
mControlPoint[5].x = mCenterPoint.x + mRadius * (1 - (0.2f - mPercent) / 0.1f * 0.5f);//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius;//左半圆
} else if (mPercent > 0 && mPercent <= 0.1) {//回弹 圆心到达
} else if (mPercent >= 0 && mPercent <= 0.1) {//回弹 圆心到达
mControlPoint[5].x = mCenterPoint.x + mRadius * (1 - (mPercent) / 0.1f * 0.5f);//右半圆
mControlPoint[0].x = mCenterPoint.x - mRadius;//左半圆
} else if (mPercent == 0) {//圆

}

}
}

Expand Down

0 comments on commit e64c362

Please sign in to comment.