Skip to content

Commit

Permalink
feat: 新增粘性小圆点指示器控件
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHubZJY committed Oct 5, 2021
1 parent 9c26ec8 commit 18190b6
Show file tree
Hide file tree
Showing 14 changed files with 551 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@
## YScratchView
常见的刮刮乐效果,支持更换底图和布局,支持刮出结果的监听
![image](https://github.com/GitHubZJY/ZJYWidget/blob/master/image/YScratchView.gif)

## YStickIndicator
可滚动的粘性小圆点指示器,切换时粘性动画效果,随当前选中下标左右滚动
![image](https://github.com/GitHubZJY/ZJYWidget/blob/master/image/YStickIndicator.gif)
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@

</activity>

<activity android:name=".sample.ScrollIndicatorTestActivity">

</activity>

</application>

</manifest>
2 changes: 2 additions & 0 deletions app/src/main/java/com/example/zjy/zjywidget/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.example.zjy.zjywidget.sample.FallingSurfaceTestActivity;
import com.example.zjy.zjywidget.sample.PayLoadingTestActivity;
import com.example.zjy.zjywidget.sample.ScratchTestActivity;
import com.example.zjy.zjywidget.sample.ScrollIndicatorTestActivity;
import com.example.zjy.zjywidget.sample.SkillViewTestActivity;
import com.example.zjy.zjywidget.sample.WaveLoadTestActivity;
import com.example.zjy.zjywidget.sample.YProfileSlideTestActivity;
Expand Down Expand Up @@ -54,6 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
viewItemBeans.add(new ViewItemBean("YBarChart", "带入场动画的柱形图表,根据输入的数据自动计算显示比例,支持自定义宽度颜色", R.raw.profile_slide, BarChartTestActivity.class));
//viewItemBeans.add(new ViewItemBean("YWheelView", "可上下滑动选择的选项菜单,支持透明度、大小的定制、边界弹性效果", R.raw.switch_view, YWheelViewActivity.class));
//viewItemBeans.add(new ViewItemBean("YSwitchView", "高仿IOS风格的开关控件,包括过渡动画,支持定制颜色、大小、切换动画时长", R.raw.switch_view, YSwitchTestActivity.class));
viewItemBeans.add(new ViewItemBean("YStickIndicator", "可滚动的粘性小圆点指示器,切换时粘性动画效果,随当前选中下标左右滚动", R.raw.stick_indicator, ScrollIndicatorTestActivity.class));

mAdapter = new EntranceItemAdapter(this, viewItemBeans);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.example.zjy.zjywidget.sample;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.zjy.zjywidget.R;
import com.zjywidget.widget.indicator.YStickIndicator;

import java.util.ArrayList;
import java.util.List;

public class ScrollIndicatorTestActivity extends AppCompatActivity {

private ViewPager viewPager;
private YStickIndicator indicator;
private Button addBtn;
List<Integer> itemList = new ArrayList<>();
MyPageAdapter pageAdapter;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll_indicator);

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle("YStickIndicator");
}

viewPager = findViewById(R.id.view_pager);
indicator = findViewById(R.id.indicator);
addBtn = findViewById(R.id.add_btn);

addBtn.setOnClickListener(view -> {
itemList.add(Color.DKGRAY);
indicator.setTotalCount(itemList.size());
viewPager.setAdapter(pageAdapter);
});

itemList.add(Color.RED);
itemList.add(Color.BLUE);
itemList.add(Color.YELLOW);
itemList.add(Color.GREEN);
itemList.add(Color.LTGRAY);
itemList.add(Color.MAGENTA);
itemList.add(Color.BLACK);
itemList.add(Color.CYAN);
pageAdapter = new MyPageAdapter(itemList);
viewPager.setAdapter(pageAdapter);

indicator.setTotalCount(itemList.size());

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
indicator.setCurIndex(position);
}

@Override
public void onPageScrollStateChanged(int state) {

}
});

}

private View generateItem(int pos, int color) {
View itemView = new View(this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
itemView.setLayoutParams(params);
itemView.setBackgroundColor(color);

itemView.setOnClickListener(view -> {
itemList.remove(pos);
indicator.setTotalCount(itemList.size());
viewPager.setAdapter(pageAdapter);
});
return itemView;
}


public class MyPageAdapter extends PagerAdapter {

private List<Integer> itemList = new ArrayList<>();

public MyPageAdapter(List<Integer> list) {
this.itemList = list;
}

@Override
public int getCount() {
return itemList.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}

@Override
public Object instantiateItem(ViewGroup container, final int position) {
View itemView = generateItem(position, itemList.get(position));
container.addView(itemView);
return itemView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_scratch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
android:layout_width="200dp"
android:layout_height="200dp"
app:scratch_drawable="@drawable/bg_scratch"
app:scratch_foreground_drawable="@drawable/fg_scratch"
/>
</FrameLayout>

Expand Down
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_scroll_indicator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">


<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintTop_toTopOf="parent" />

<com.zjywidget.widget.indicator.YStickIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/view_pager"
android:layout_marginBottom="10dp"
app:stick_indicator_small_dot_width="8dp"
app:stick_indicator_big_dot_width="10dp"
app:stick_indicator_dot_padding="6dp"/>

<Button
android:id="@+id/add_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="添加"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/view_pager"/>


</androidx.constraintlayout.widget.ConstraintLayout>
Binary file added app/src/main/res/raw/stick_indicator.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.32'
ext.kotlin_version = '1.5.0'

repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip
Binary file added image/YStickIndicator.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions widget/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
Expand All @@ -23,6 +23,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

Expand All @@ -36,6 +40,6 @@ dependencies {

api 'com.github.bumptech.glide:glide:4.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.core:core-ktx:+"
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Loading

0 comments on commit 18190b6

Please sign in to comment.