2017-03-07 79 views
-3
<android.support.design.widget.FloatingActionButton 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    app:fabSize="normal" 
    app:srcCompat="@mipmap/ic_launcher" 
    android:id="@+id/floatingActionButton" 
    android:layout_gravity="bottom|end" 
    android:layout_marginRight="20dp" 
    android:layout_marginBottom="20dp" 
    app:backgroundTint="#54ddde" /> 

目前,浮動按鈕的圖像是android。但我想改變爲'加'形象。java.lang.RuntimeException:Canvas:試圖繪製太大的位圖

般這個

<android.support.design.widget.FloatingActionButton 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    app:fabSize="normal" 
    android:src="@drawable/img_plus" 
    android:id="@+id/floatingActionButton" 
    android:layout_gravity="bottom|end" 
    android:layout_marginRight="20dp" 
    android:layout_marginBottom="20dp" 
    app:backgroundTint="#54ddde" /> 

但是我只改變形象,應用程序已經停止。我真的很尷尬。 有人可以幫助我。

java.lang.RuntimeException: Canvas: trying to draw too large(110250000bytes) bitmap. 
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260) 
at android.graphics.Canvas.drawBitmap(Canvas.java:1420) 
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545) 
at android.widget.ImageView.onDraw(ImageView.java:1286) 
at android.view.View.draw(View.java:18313) 
at android.view.View.updateDisplayListIfDirty(View.java:17291) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.draw(View.java:18316) 
at android.widget.ScrollView.draw(ScrollView.java:2774) 
at android.view.View.updateDisplayListIfDirty(View.java:17291) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.updateDisplayListIfDirty(View.java:17286) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.updateDisplayListIfDirty(View.java:17286) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.updateDisplayListIfDirty(View.java:17286) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.updateDisplayListIfDirty(View.java:17286) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.updateDisplayListIfDirty(View.java:17286) 
at android.view.View.draw(View.java:18075) 
at android.view.ViewGroup.drawChild(ViewGroup.java:3966) 
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752) 
at android.view.View.draw(View.java:18316) 
at com.android.internal.policy.DecorView.draw(DecorView.java:850) 
at android.view.View.updateDisplayListIfDirty(View.java:17291) 
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:666) 
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:672) 
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:780) 
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3093) 
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2889) 
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2483) 
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1490) 
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7027) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927) 
at android.view.Choreographer.doCallbacks(Choreographer.java:702) 
at android.view.Choreographer.doFrame(Choreographer.java:638) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6688) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 

這裏是日誌貓的錯誤。

+0

發佈錯誤.. –

+0

你有錯誤日誌嗎? – TruongHieu

+0

確保您的img_plus是PNG – Aroniez

回答

0

做它progamatically,試試這個。

ImageView icon = new ImageView(this); // Create an icon 
    icon.setImageDrawable(getResources().getDrawable(R.drawable.add_user)); 

    //set the appropriate background for the main floating action button along with its icon 
    FloatingActionButton factionButton = new FloatingActionButton.Builder(this) 
      .setContentView(icon) 
      .setBackgroundDrawable(R.drawable.selector_floating_button) 
      .build();