[android-developers] Re: Building composed shapes
UPDATE: I have been able to write (layers.xml) what I want on a XML file using Layer-List. so I can use this drawable on a ImageView normally doing: ImageView android:layout_height=wrap_content android:layout_width=wrap_content android:src=@drawable/layers / Everything works fine! But this isn't my aim. Actually I'd like to use this drawable as a background of my custom view, so I need to use it into the onDraw() method applying it on the canvas of my View. ... Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.layers); canvas.drawBitmap(img, null, rect, paint); ... I've this error at runtime: 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): java.lang.NullPointerException 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at android.graphics.Canvas.throwIfRecycled(Canvas.java:954) 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at android.graphics.Canvas.drawBitmap(Canvas.java:1012) 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at it.myPackageTest.view.test.CustomView.onDraw(CustomView.java:79) ... I don't call recycle(), so how it is possible? Maybe I can't use layers on a canvas? I really don't know! :( Please tell me something! Thanks in advance! On 30 Mag, 18:50, Paolo brand...@gmail.com wrote: Hi there! I need to draw a drawable on a canvas. I'd like to avoid using a png file, but I'd like to draw it with shapes. The final result must be an unique drawable composed by two rects overlayed, one smallest than the other one. How can I do that in XML? I've seen layer-list but I can't figure out if it is useful for my achivement besides the fact I have a runtime exception... .:( Can anyone hepl me, please? Thanks in advance. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Building composed shapes
UPDATE 2: I found out the problem! BitmapFactory.decodeResource(context.getResources(), R.drawable.layers); return always NULL, what could be the problem for you? On 31 Mag, 11:15, Paolo brand...@gmail.com wrote: UPDATE: I have been able to write (layers.xml) what I want on a XML file using Layer-List. so I can use this drawable on a ImageView normally doing: ImageView android:layout_height=wrap_content android:layout_width=wrap_content android:src=@drawable/layers / Everything works fine! But this isn't my aim. Actually I'd like to use this drawable as a background of my custom view, so I need to use it into the onDraw() method applying it on the canvas of my View. ... Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.layers); canvas.drawBitmap(img, null, rect, paint); ... I've this error at runtime: 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): java.lang.NullPointerException 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at android.graphics.Canvas.throwIfRecycled(Canvas.java:954) 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at android.graphics.Canvas.drawBitmap(Canvas.java:1012) 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at it.myPackageTest.view.test.CustomView.onDraw(CustomView.java:79) ... I don't call recycle(), so how it is possible? Maybe I can't use layers on a canvas? I really don't know! :( Please tell me something! Thanks in advance! On 30 Mag, 18:50, Paolo brand...@gmail.com wrote: Hi there! I need to draw a drawable on a canvas. I'd like to avoid using a png file, but I'd like to draw it with shapes. The final result must be an unique drawable composed by two rects overlayed, one smallest than the other one. How can I do that in XML? I've seen layer-list but I can't figure out if it is useful for my achivement besides the fact I have a runtime exception... .:( Can anyone hepl me, please? Thanks in advance. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Building composed shapes
SOLUTION: layer = (LayerDrawable) getResources().getDrawable(R.drawable.layers); layer.setBounds(** what you want **); layer.mutate(); layer.draw(canvas); On 31 Mag, 11:29, Paolo brand...@gmail.com wrote: UPDATE 2: I found out the problem! BitmapFactory.decodeResource(context.getResources(), R.drawable.layers); return always NULL, what could be the problem for you? On 31 Mag, 11:15, Paolo brand...@gmail.com wrote: UPDATE: I have been able to write (layers.xml) what I want on a XML file using Layer-List. so I can use this drawable on a ImageView normally doing: ImageView android:layout_height=wrap_content android:layout_width=wrap_content android:src=@drawable/layers / Everything works fine! But this isn't my aim. Actually I'd like to use this drawable as a background of my custom view, so I need to use it into the onDraw() method applying it on the canvas of my View. ... Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.layers); canvas.drawBitmap(img, null, rect, paint); ... I've this error at runtime: 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): java.lang.NullPointerException 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at android.graphics.Canvas.throwIfRecycled(Canvas.java:954) 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at android.graphics.Canvas.drawBitmap(Canvas.java:1012) 05-31 10:59:35.289: ERROR/AndroidRuntime(1702): at it.myPackageTest.view.test.CustomView.onDraw(CustomView.java:79) ... I don't call recycle(), so how it is possible? Maybe I can't use layers on a canvas? I really don't know! :( Please tell me something! Thanks in advance! On 30 Mag, 18:50, Paolo brand...@gmail.com wrote: Hi there! I need to draw a drawable on a canvas. I'd like to avoid using a png file, but I'd like to draw it with shapes. The final result must be an unique drawable composed by two rects overlayed, one smallest than the other one. How can I do that in XML? I've seen layer-list but I can't figure out if it is useful for my achivement besides the fact I have a runtime exception... .:( Can anyone hepl me, please? Thanks in advance. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en