I want to create a custom View similar to this image. More specifically, the dark "number of riders" view. I don't want to use an image for background. I need a drawable xml for the background.
I am new to Android so any help would be appreciated.
The best way to do that will be to use a 9-patch drawable file and set it as the background of the TextView.
Here is how you can do that: http://en.miui.com/thread-26099-1-1.html
Or you can create an SVG and use that as background. The easiest way to do that would be to make a png image and convert it to SVG file using online converters.
How to convert a PNG image to a SVG?
There is more complicated way to archive it like drawing on a canvas and using that as background, But I would recommend you to use 9-patch file.
Related
How can I add a blur effect on a drawable image placed in the image view object of a layout, using xml not Java? I want to code this blur effect in XML.
It is not currently possible to produce a blur effect within the layout XML of an Android application.
However, it is possible through the use of Java. There are a number of techniques available to do this (see here for a recent guide on how to do this effectively). Usually either Renderscript or the re-scaling of the image is used to generate a blur of the image.
Edit:
It may now be possible to achieve a blur solely by adding an XML property through the use of a custom data binding adapter. Check out the data binding library for more on how to create an adapter
After finding Display SVG Image in image view in android on Google and going to Having issue on Real Device using vector image in android. SVG-android, I find that "You need a 3rd-party JAR to do it" is a bit of overkill. Is there any way to render an SVG without using 3rd-party libraries?
I managed to display an SVG using a WebView, since that is more than capable of rendering an SVG:
webView.loadUrl("file:///android_res/drawable/file.svg"); // point it to the SVG
webView.setBackgroundColor(0x00000000); // set the background to transparent
This makes it render much like a transparent PNG would in an ImageView. The only caveat is that the SVG must use the viewBox attribute and not use the height or width attributes, to ensure it resizes properly.
Using custom fonts actually works really well in Android.
You can use the free icomoon web application to convert SVGs to custom .ttf font characters.
If you are using it for imagePicker sort of feature then,
webView.loadURl(selectedFileLocation.toString)
else if it is to display a .svg image from web,
webView.loadURl(/*url for the .svg file*/)
In my app i have to set up a small image as background, to show text and image on it.
1)I tried to set image as background of a layout some thing like
<layout android:background="imagePath"> <ImageView/> <TextView/></layout>
2)Tried to show image in web view.
But the image has lost its quality. In iphone we can resiz it like stretchableImageWithLeftCapWidth:23.0f topCapHeight:15.0
i want to know what should be the best method for image resizing in android
Best way to do stretchable background is 9-patch drawable. Android sdk provides instrument for simple creating 9-patches.
Using this you have to manage part of Image which not losing quality.
Best way to do stretchable background is 9-patch drawable. Android sdk provides instrument for simple creating 9-patches.
I drew up a custom drawable icon in MS paint, but when I load the image it has a white background instead of transparent, how do I fix this?
MS Paint probably saved this without a transparent background. Id recommend using something like GIMP or Paint.NET to create this icon. They are both available free.
You probably need to save it as either a .gif file or a .png file too, as these are compatible with transparency (and Android).
I think you have to use better editor for your purposes, which could make the background of your image transparent. MS Paint has no such possibilities.
I want to set a specific background image for all my buttons.
So, I changed my PNG file into a Ninepatch drawable using the "draw9patch" tool(by specifying the line of strecth).
Then, I applied this as background to my button using
"myBtn.setBackgroundResource(R.drawable.new_png);"
Now, the background appears for the button, but the lines of stretch are also visible on the android screen, wherever I'd specified them in the tool.
Can you help? Is there something wrong in how I'm using the tool?
Ninepatch png files must be named with a special naming convention: for instance in your example, new_png.9.png. When you refer to the drawable in your code, you exclude the '.9.png', so your code would not need to change, only the image file name needs to change.