Created nine patch image via Android Studio from png file. Set patch image as background on ImageView, but ImageView shows with greater size as expected. Studio shows that image has size 117*95, but on display imageView shows with size near 334*266.
Please, help how to fix it. Png and screens attached.
<ImageView android:background="#drawable/new_sent_bubble_edit1" android:layout_width="wrap_content" android:layout_height="wrap_content" />
nine patch view in studio
Found solution. Just need to put 9 patch file to some density drawable folder. When put picture to xxhdpi-drawable folder and image has been drawn as expected.
Related
i don't know what is the problem with my android studio i am trying to add an image from image view ..it is showing in design tab but not in emulator ...i am a newbie ..please help me fix it ..thanksAndroid Studio
i tried fixing it by changing the attributes but didnt work ..
You are setting a sample_image to an imageView. To set an image, give it a real source.
android:src="#drawable/any_image"
give source of an image drawable
Download any jpg or png image from google and paste that image in drawable folder than add this line in to you imageview widget -> android:src="#drawable/TestImage"
like this->
<ImageView
android:id="#+id/imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="#drawable/TestImage">
I have an ImageView which I display on screen, the quality on the edges is not smooth, this is on emulator and on real device.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/temp_9" />
I have attached a picture to show the difference with the image on the left being from emulator (sharp edges) and the image on the right is the original PNG image (smooth edges).
I have placed image in raw instead of drawable - not working
I have moved the image across the different drawable folders - not working
I have created a generic 'drawable' folder and placed image inside - not working
I have created a 9 path image - not working
I have reduced the image size using GIMP - not working
I have one big image named panel_bck.jpg to use in different resolutions to decrease apk size. The image format is JPG and it's size is 1.9MB. I put it to default drawable folder only. But when I set the background in code, the BitmapFactory can't find the image at
drawable/panel_bck.jpg
and the result is all black background. I tested this case with other images(PNG files, JPG files) and there is no problem with them. Only question is that a limitation exist for the drawable size or what is the problem? How can I solve this?
If your image very big resoulation you will set drawable-xxhdpi directory only.
I had a problem like yours trying to maka a big image fit into a too small ImageView and I fixed my problem by using this line in the layout xml file:
android:adjustViewBounds="true"
I don't know if it can ba applied to an activity background though.
You should use 9patch image. You can create 9patch image by using the tool called draw9patch located in sdk/tools. First create a large resolution image and give to draw9patch it will create a 9patch image with extension .9.png add that image in drawable it will solve you problem.
See following links for detail
http://developer.android.com/tools/help/draw9patch.html
http://codesignature.com/how-to-design-9-patch-buttons-for-android-using-adobe-photoshop-for-all-pixel-densities-and-states/
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.
I am creating 9 patch images using draw9patch tool and saving images with extension .9.png but when I am using created 9 patch images in app it is giving error.
But when I downloaded an 9 patch image from net & used in my same app it is working properly.
I am not getting what I am doing wrong .
Please Help
You must be creating the 9-patch wrongly. I had also the same issue . You must be drawing the black patch on one side of image. Try to draw the black patch by dragging your mouse two side of image. I hope you can understand my words...........
Nine-patch images on Android must have transparent 1-pixel edge, and have opaque pixels in left-top border (1 pixel wide) specifying which part of image is stretched, and which do not.
More here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch