@@ -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 );
0 commit comments