I have a ninepatch image (speech bubble) that should surround a text. When I set the background of the textview the bubble is shown as it should be without specifying width or height (it should adjust to the content of the text). My problem is that when a read the exact same image from disk the image is resized.
I've read a lot of different answers here on stackoverflow, but haven't found any solution that actually works for me.
xml-file:
<TextView
android:id="@+id/someText"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="@android:color/background_dark"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a a line. "
/>
I've tried adjusting the image (as suggested on here) the following:
private Drawable adjustImage(Drawable image){
if(image == null)
return null;
Bitmap bitmapOrg = ((BitmapDrawable) image).getBitmap();
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
Matrix matrix = new Matrix();
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
return new BitmapDrawable(resizedBitmap);
}
Also tried another suggested solution:
TypedValue typedValue = new TypedValue();
//density none divides by the density, density default keeps the original size
typedValue.density = TypedValue.DENSITY_DEFAULT;
Drawable d = Drawable.createFromResourceStream(null, typedValue, fis, "test");'
But neither solution works for me. Anyone knows what I'm missing here?
Thanks.