Skip to content

Commit 8e564e6

Browse files
committed
Merge branch 'dev' of https://github.com/luiing/StackViewLayout into dev
2 parents dcf530f + 5f563b5 commit 8e564e6

4 files changed

Lines changed: 32 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
![效果图](/pic/demo20.gif)
1010

1111
### Use
12-
implementation 'com.uis:stacklayout:0.1.2'
12+
implementation 'com.uis:stacklayout:0.2.0'
1313

1414
*Name*| *Descript*|*Value*
1515
-----|--------|---
@@ -81,8 +81,7 @@ stackEdgeModel|层叠位置|left/right
8181
stackViewLayout.setPosition(position+3);
8282
}
8383
});
84-
stackViewLayout.setPosition(10);
85-
//装载异步数据需要调用 stackViewLayout.notifyDataChanged();
84+
stackViewLayout.setPosition(10);//指定位置
8685
```
8786

8887
### Version
@@ -93,6 +92,7 @@ stackEdgeModel|层叠位置|left/right
9392
0.1.0|zoomX,zoomY呈等比数列|更改属性
9493
0.1.1|只有一条数据时|fixed
9594
0.1.2|增加动画、轮播时间设置,获取当前选中位置|新增方法
95+
0.2.0|只有一个元素,不支持轮播和滑动|新增功能
9696

9797
### Thanks
9898

stacklayout/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ dependencies {
2323
implementation fileTree(dir: 'libs', include: ['*.jar'])
2424
}
2525

26-
//apply from: '../../../bintray.gradle'
26+
apply from: '../../../bintray.gradle'

stacklayout/src/main/java/com/uis/stackview/StackHelper.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,21 @@ void bindLayout(StackLayout layout) {
6161
setAutoPlay(this.layout.stackLooper);
6262
}
6363

64+
int getItemCount(){
65+
int cnt = 0;
66+
if(layout != null && layout.getAdapter() != null){
67+
cnt = layout.getAdapter().getItemCount();
68+
}
69+
return cnt;
70+
}
71+
6472
void unbindLayout() {
6573
setAutoPlay(false);
6674
}
6775

6876
void measureChild(int width,int height){
6977
//log("measue...");
70-
if(layout != null && layout.getAdapter() != null && layout.getAdapter().getItemCount() > 0 ){
78+
if(getItemCount() > 0 ){
7179
int size = layout.getRealStackSize();
7280
if(originX.isEmpty()) {
7381
float stackSpaces = 0;
@@ -305,7 +313,7 @@ void setAutoPlay(boolean looper){
305313
if(executor == null || executor.isShutdown()){
306314
executor = new ScheduledThreadPoolExecutor(2);
307315
}
308-
if(executor.getQueue().size() <= 0) {
316+
if(executor.getQueue().size() <= 0 && getItemCount() > 1) {
309317
executor.scheduleWithFixedDelay(new AutoRunnable(this), 2000, mDelay, TimeUnit.MILLISECONDS);
310318
}
311319
}else {
@@ -317,7 +325,7 @@ void setAutoPlay(boolean looper){
317325

318326
/** 加入底层 */
319327
private void addBottomView(){
320-
int cnt = layout.getAdapter().getItemCount();
328+
int cnt = getItemCount();
321329
int stackSize = layout.getRealStackSize();
322330
displayPosition += 1;
323331
displayPosition %= cnt;
@@ -331,7 +339,7 @@ private void addBottomView(){
331339

332340
/** 加入顶层 */
333341
private View addTopView(){
334-
int cnt = layout.getAdapter().getItemCount();
342+
int cnt = getItemCount();
335343
int position = displayPosition - 1;
336344
if(position < 0){
337345
position += cnt;
@@ -345,7 +353,7 @@ private View addTopView(){
345353

346354
/** 移除底层 */
347355
private void removeBottomView(){
348-
int cnt = layout.getAdapter().getItemCount();
356+
int cnt = getItemCount();
349357
displayPosition -= 1;
350358
if(displayPosition < 0){
351359
displayPosition += cnt;
@@ -447,7 +455,7 @@ static class AutoRunnable implements Runnable{
447455

448456
@Override
449457
public void run() {
450-
if(helper.layout != null && helper.layout.getAdapter() != null && helper.layout.getChildCount() > 0){
458+
if(helper.getItemCount() > 1 && helper.layout.getChildCount() > 0){
451459
final StackLayout stack = helper.layout;
452460
int[] points = new int[2];
453461
stack.getLocationInWindow(points);

stacklayout/src/main/java/com/uis/stackview/StackLayout.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public void setStackLooper(boolean looper){
123123
public void setAdapter(StackAdapter adapter) {
124124
this.adapter = adapter;
125125
removeAllViewsInLayout();
126+
notifyDataChanged();
126127
}
127128

128129
public StackAdapter getAdapter(){
@@ -188,20 +189,24 @@ public boolean onTouchEvent(MotionEvent event) {
188189
stackHelper.fingerTouchDown();
189190
break;
190191
case MotionEvent.ACTION_MOVE:
191-
if(stackHelper.canScroll(downX,downY,event.getX(),event.getY())) {
192-
int currentX = (int) event.getX();
193-
int dx = (int) (currentX - lastX);
194-
stackHelper.executeScroll(dx);
195-
lastX = currentX;
192+
if(adapter != null && adapter.getItemCount() > 1) {
193+
if (stackHelper.canScroll(downX, downY, event.getX(), event.getY())) {
194+
int currentX = (int) event.getX();
195+
int dx = (int) (currentX - lastX);
196+
stackHelper.executeScroll(dx);
197+
lastX = currentX;
198+
}
196199
}
197200
break;
198201
case MotionEvent.ACTION_UP:
199202
handleItemClicked();
200203
case MotionEvent.ACTION_CANCEL:
201-
mVelocity.computeCurrentVelocity(1000, mMaximumVelocity);
202-
int velocity = (int) mVelocity.getXVelocity();
203-
stackHelper.releaseScroll(velocity);
204-
recycleVelocityTracker();
204+
if(adapter != null && adapter.getItemCount() > 1) {
205+
mVelocity.computeCurrentVelocity(1000, mMaximumVelocity);
206+
int velocity = (int) mVelocity.getXVelocity();
207+
stackHelper.releaseScroll(velocity);
208+
recycleVelocityTracker();
209+
}
205210
default:
206211
}
207212
return true;

0 commit comments

Comments
 (0)