2016-06-21 8 views
2

EditTextを移動してサイズ変更できるようにカスタムEditTextを作成しました。それは私の電話で働いているが、私が入力を開始すると、他の電話でクラッシュした。私は、XMLコードにandroid:inputType="text"を追加するとEditextはIndexOutOfBound例外を返します

は、それが働いていたが、アプリケーションの全体の目的は、ここで完全なスタックエラーここ

java.lang.IndexOutOfBoundsException 
    at android.graphics.Paint.getTextRunAdvances(Paint.java:1841) 
    at android.graphics.Paint.getTextRunAdvances(Paint.java:1818) 
    at android.text.TextLine.handleText(TextLine.java:755) 
    at android.text.TextLine.handleRun(TextLine.java:907) 
    at android.text.TextLine.measureRun(TextLine.java:414) 
    at android.text.TextLine.measure(TextLine.java:293) 
    at android.text.TextLine.metrics(TextLine.java:267) 
    at android.text.Layout.getLineExtent(Layout.java:977) 
    at android.text.Layout.drawText(Layout.java:329) 
    at android.widget.Editor.drawHardwareAccelerated(Editor.java:1384) 
    at android.widget.Editor.onDraw(Editor.java:1298) 
    at android.widget.TextView.onDraw(TextView.java:5061) 
    at com.oluwayomi.quotage.custom.DragEditText.onDraw(DragEditText.java:340) 
    at android.view.View.draw(View.java:13917) 
    at android.view.View.getDisplayList(View.java:12832) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3019) 
    at android.view.View.getDisplayList(View.java:12755) 
    at android.view.View.getDisplayList(View.java:12876) 
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1249) 
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2520) 
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2387) 
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2189) 
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1181) 
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4942) 
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776) 
    at android.view.Choreographer.doCallbacks(Choreographer.java:579) 
    at android.view.Choreographer.doFrame(Choreographer.java:548) 
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762) 
    at android.os.Handler.handleCallback(Handler.java:800) 
    at android.os.Handler.dispatchMessage(Handler.java:100) 
    at android.os.Looper.loop(Looper.java:194) 
    at android.app.ActivityThread.main(ActivityThread.java:5370) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:525) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
    at dalvik.system.NativeStart.main(Native Method) 

があるXMLコード

ここ
<RelativeLayout 
      android:id="@+id/TextRoot" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <com.oluwayomi.quotage.custom.DragEditText 
       android:id="@+id/etText" 
       style="@style/Widget.AppCompat.Button.Borderless" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_gravity="center" 
       android:layout_marginTop="124dp" 
       android:background="@drawable/null_background" 
       android:gravity="center" 
       android:padding="10dp" 
       android:hint="Type text here.\n Double tap to edit \n and long press to resize." 
       android:textSize="22sp" /> 
     </RelativeLayout> 

を をされて失われました私のカスタムEditTextのコードです

public DragEditText(Context context) { 
     this(context, null); 

    } 

    public DragEditText(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     mPaintFrame = new Paint(); 
     mPaintTranslucent = new Paint(); 
     c = context; 

     RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
     this.setLayoutParams(layoutParams); 
    } 

    public DragEditText(Context context, AttributeSet attrs, int defStyleAttr) { 
     this(context, attrs); 

    } @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     int viewWidth = MeasureSpec.getSize(widthMeasureSpec); 
     int viewHeight = MeasureSpec.getSize(heightMeasureSpec); 

     mParentWidth = c.getResources().getDisplayMetrics().widthPixels; 
     mParentHeight = c.getResources().getDisplayMetrics().heightPixels; 
     mParentRect = new RectF(0, 0, viewWidth, viewHeight); 
    } 
@Override 
    protected void onDraw(Canvas canvas) { 
     drawDragFrame(canvas); 
     super.onDraw(canvas); 
    } 
    private void drawDragFrame(Canvas canvas) { 
      if (showResizeFrame) { 
       drawFrame(canvas); 
       drawHandleShadows(canvas); 
       drawHandles(canvas); 
      } else if (showDragFrame) { 
       drawHighlight(canvas); 
      } 
     } 

     private void drawFrame(Canvas canvas) { 
      mPaintFrame.setAntiAlias(true); 
      mPaintFrame.setFilterBitmap(true); 
      mPaintFrame.setStyle(Paint.Style.STROKE); 
      mPaintFrame.setColor(getResources().getColor(R.color.colorAccent)); 
      mPaintFrame.setStrokeWidth(1); 
      canvas.drawRect(mFrameRect.left + mHandleSize/2, mFrameRect.top, mFrameRect.right - mHandleSize/2, mFrameRect.bottom, mPaintFrame); 
     } 

     private void drawHighlight(Canvas canvas) { 
      mPaintTranslucent.setAntiAlias(true); 
      mPaintTranslucent.setFilterBitmap(true); 
      mPaintTranslucent.setStyle(Paint.Style.FILL); 
      mPaintTranslucent.setColor(TRANSLUCENT_WHITE); 
      mPaintTranslucent.setStrokeWidth(1); 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       canvas.drawRoundRect(mFrameRect.left, mFrameRect.top, mFrameRect.right - mHandleSize, mFrameRect.bottom, mHandleSize, mHandleSize, mPaintTranslucent); 
      } else 
       canvas.drawRect(mFrameRect.left, mFrameRect.top, mFrameRect.right - mHandleSize, mFrameRect.bottom, mPaintTranslucent); 
     } 

     private void drawHandles(Canvas canvas) { 
      //drawHandleShadows(canvas); 
      mPaintFrame.setStyle(Paint.Style.FILL_AND_STROKE); 
      mPaintFrame.setColor(getResources().getColor(R.color.colorAccent)); 


      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       canvas.drawRoundRect(mFrameRect.left, mFrameRect.top + mHandleSize, mFrameRect.left + mHandleSize, mFrameRect.bottom - mHandleSize, mHandleSize/2, mHandleSize/2, mPaintFrame); 
       canvas.drawRoundRect(mFrameRect.right - mHandleSize, mFrameRect.top + mHandleSize, mFrameRect.right, mFrameRect.bottom - mHandleSize, mHandleSize/2, mHandleSize/2, mPaintFrame); 
      } else { 
       canvas.drawRect(mFrameRect.left, mFrameRect.top + mHandleSize, mFrameRect.left + mHandleSize, mFrameRect.bottom - mHandleSize, mPaintFrame); 
       canvas.drawRect(mFrameRect.right - mHandleSize, mFrameRect.top + mHandleSize, mFrameRect.right, mFrameRect.bottom - mHandleSize, mPaintFrame); 
      } 

     } 

     private void drawHandleShadows(Canvas canvas) { 
      mPaintFrame.setStyle(Paint.Style.FILL); 
      mPaintFrame.setColor(TRANSLUCENT_BLACK); 
      RectF rect = new RectF(mFrameRect); 
      rect.offset(0, 1); 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       canvas.drawRoundRect(rect.left, rect.top + mHandleSize, rect.left + mHandleSize, rect.bottom - mHandleSize, mHandleSize/2, mHandleSize/2, mPaintFrame); 
       canvas.drawRoundRect(rect.right - mHandleSize, rect.top + mHandleSize, rect.right, rect.bottom - mHandleSize, mHandleSize/2, mHandleSize/2, mPaintFrame); 
      } else { 
       canvas.drawRect(rect.left, rect.top + mHandleSize, rect.left + mHandleSize, rect.bottom - mHandleSize, mPaintFrame); 
       canvas.drawRect(rect.right - mHandleSize, rect.top + mHandleSize, rect.right, rect.bottom - mHandleSize, mPaintFrame); 
      } 
    } 
+0

アンドロイドを除去することで、\ nはヒント –

+0

の試みをを除去して試してみる:重力=「センター」 – Krutik

+0

私はそれを削除したが、それはまだDragEditText.java' 'のjava.lang.IndexOutOfBoundsException –

答えて

0

Afte r役立つ解決策を見ずに検索しましたが、ついにこの問題が発見されました

style="@style/Widget.AppCompat.Button.Borderless" 

EditTextは適用できません。

ありがとうございました。

関連する問題