Layer List Drawable - clip bitmap by nine-patch? - android

I would like to create Drawable that contains nine-patch and a Bitmap.
I put them together in Layer List Drawable, but it turns out that Bitmap is extending nine-patch beyond the edge.
Is there any way to "cut" Bitmap so it won't be overlapping nine-patch?
EDIT: Actually it seems that I would like to shrink background to wrap content and ingore big bitmap in background.

a nine patch by definition doesn't have a size.
From the sounds of things you haven't configured your nine patch correctly.
Please attach an image of what you're seeing and your source files.

Related

How to create drawable in xml, with inverse rounding?

I need to create in xml next drawable:
How can I achieve this?
I only know how to make right-top rounding - but what about bottom-right inverse rounding?
You should use a nine patch image to do this.
https://developer.android.com/studio/write/draw9patch.html
Example tool:
https://romannurik.github.io/AndroidAssetStudio/nine-patches.html#&sourceDensity=320&name=example
A nine patch is a png image with black pixels in the borders to delimitate the area that has to be extended. The format is example.9.png, .9.png is the extension.
A little tutorial, you can find others:
https://www.youtube.com/watch?v=wLimJf-EIl8

ImageView bitmap is stretched after activity transition

Is there any specific reason why this is happening?
This is the image after the transition happens.
You haven't provided any code to help us diagnose your problem, but your terrifying image (that looks like Jim Carrey) may be related to the tileMode. Your image looks like it's exhibiting clamping.
Clamping is when the edge color is replicated if the bitmap for an ImageView is smaller in size than the ImageView. These are all the options, along with a suitable picture of Jim:
disabled - Do not tile the bitmap. This is the default value.
clamp - Replicates the edge color.
repeat - Repeats the bitmap in both direction.
mirror - Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam.
Since it looks like your Bitmap is smaller than your ImageView and I don't think you actually want to use any tile mode (just use the default of disabled), I'd recommend either:
A) Use ImageView's setScaleType() so that the Bitmap resizes to fill the ImageView, using the centerCrop value (though check this blog for more examples), or...
B) Make your Bitmap larger
(I'd recommend A)

repeat texture between a png

I want to repeat specific rectangular area at centre of png drawable instead of repeating the whole image using
android:tileMode="repeat" . If I 9 patch it will get stretched .any solution ?
Either, offline create a new PNG that only consists of the area you want, or dynamically, create a new Bitmap from the area you want and use this image for a drawable.

Nine patch images look pixelated

I use several nine patch images in my layout, for buttons, text fields and form backgrounds. All of the xxx.9.png files are in the drawable-hdpi folder, just like the regular images, yet they still look pixelated.
The ImageView at the top has a regular bitmap and the lower ImageView uses a Nine Patch bitmap. You can see that the Nine Patch bitmap is scaled to a lower density. How do I fix that?
You should put 9 patch images in the nodpi folder, unless you want the non-stretchable area to be scaled/stretched also.
Ah, it was messed up because I was calling canvas.setDensity( 480 ) somewhere in a custom view. That caused this problem.

9-patch bitmap on a widget using RemoteViews

I have a widget with an ImageView on it. I set this ImageView to a Bitmap created from a 9-patch PNG resource. The image is set correctly but is not stretched correctly - i.e. the whole image is stretched instead of just part like defined in my 9-patch PNG. If I just set the 9-patch image as a resource, it works. How can I fix this?
// Does not work (9-patch does not display correctly)
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.someNinePatch);
remoteViews.setImageViewBitmap(R.id.someImageView, bitmap);
// Works (9-patch displays correctly)
remoteViews.setImageViewResource(R.id.someImageView, R.drawable.someNinePatch);
Android knows a PNG is a nine-patch by virtue of the .9.png file extension on the resource. I do not know of any way to use nine-patch images outside of resources, because Android will not have the file extension and will not know the image is a nine-patch.

Categories

Resources