2015-05-01 49 views
2

由於某種原因,我在幾個設備上出現此錯誤,例如:是google nexus 10或lg g3。IllegalArgumentException:佈局:-998896 <0 in showcaseview

這是產生這種錯誤代碼:

mPlusButton.setClickable(false); 
      guide.setVisibility(View.INVISIBLE); 
      final RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT); 
      lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
      lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT); 
      lps.setMargins(40,0,0,160); 

      mViews1 = new ShowcaseView.Builder(this) 
        .setStyle(R.style.CustomShowcaseTheme3) 
        .setContentTitle("Welcome to listo") 
        .setContentText("The best way to share your to-do lists\nand manage them in just a few clicks!") 
        .setOnClickListener(new View.OnClickListener() { 
         @Override 
         public void onClick(View v) { 

          if(showcase_num == 0){ 
           showcase_num++; 
           mViews1.setTarget(new ViewTarget(R.id.fab,MainActivity.this)); 
           mViews1.setContentTitle("Manage your lists"); 
           mViews1.setContentText("Press on the plus button to add a new list.\nLong press on a list to exit from it, rename, mute or delete it." + 
             "\n\nAt both sides of the list's name you can see the number of participants and tasks on it."); 
           mViews1.setButtonText("Got it!"); 

          }else{ 
           mViews1.hide(); 
           mViews1.destroyDrawingCache(); 
           mPlusButton.setClickable(true); 

           updateList(false); 

           SharedPreferences.Editor editor = prefs.edit(); 
           editor.putInt("showcase_key", 0); 
           editor.commit(); 
          } 

         } 
        }) 
        .doNotBlockTouches() 
        .build(); 

      mViews1.setButtonText("I'm ready"); 
      mViews1.setButtonPosition(lps); 

我沒有在互聯網上找到任何解決方案。據我瞭解,由於某些原因,佈局具有導致Layout.java類拋出異常負值...

+0

我有同樣的錯誤。你有沒有找到解決辦法? –

+0

這是SnowcaseView的一個已知問題:https://github.com/amlcurran/ShowcaseView/issues/182。如果沒有幫助,請嘗試提供的解決方案並將代碼添加到此問題。 – birdy

回答

1

我發現了ShowCaseView項目的github上的解決方案: https://github.com/amlcurran/ShowcaseView/issues/225

這是一個尚未在主分支上修復的錯誤,因此您需要自己編輯庫。轉到「TextDrawer」類,並用此替換draw()方法:

public void draw(Canvas canvas) { 
    if (shouldDrawText()) { 

     float[] textPosition = getBestTextPosition(); 

     // ADDED FIX FOR LG G3 
     // @author CollegeDev 
     for (float position : textPosition) { 
      if (position < 0) { 
       return; 
      } 
     } 

     if (!TextUtils.isEmpty(mTitle)) { 
      canvas.save(); 
      if (hasRecalculated) { 
       mDynamicTitleLayout = new DynamicLayout(mTitle, titlePaint, 
         (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 
         1.0f, 1.0f, true); 
      } 
      if (mDynamicTitleLayout != null) { 
       canvas.translate(textPosition[0], textPosition[1]); 
       mDynamicTitleLayout.draw(canvas); 
       canvas.restore(); 
      } 
     } 

     if (!TextUtils.isEmpty(mDetails)) { 
      canvas.save(); 
      if (hasRecalculated) { 
       mDynamicDetailLayout = new DynamicLayout(mDetails, textPaint, 
         (int) textPosition[2], 
         Layout.Alignment.ALIGN_NORMAL, 
         1.2f, 1.0f, true); 
      } 
      float offsetForTitle = mDynamicTitleLayout != null ? mDynamicTitleLayout.getHeight() : 
        0; 
      if (mDynamicDetailLayout != null) { 
       canvas.translate(textPosition[0], textPosition[1] + offsetForTitle); 
       mDynamicDetailLayout.draw(canvas); 
       canvas.restore(); 
      } 

     } 
    } 
    hasRecalculated = false; 
} 
+0

我改進了,請再次檢查。 – kundasaba

+0

感謝您的編輯 – Drew