Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a kind of simple donut chart gradually colored. I want this donut be faded depending on a value. For example if the value is 35 then 35 % of my donut would be not faded and 65 % would be faded. I don't want any animation.
This is an example of what I want to achieve :
The code for the donut without the masking feature :
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/donut"
android:layout_alignTop="#+id/imageView"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"/>
I don't know android designing but some web design logic may help.
Could you create a non-transparent panel over the image and give it the exact width and height of the image. So when you wish to display 20% of the image, you just giv to the panel 80% and align it properly.
Best regards.
You could also use some masking in combination with a semi-transparent image using the following steps.
create a black/white donut up to e.g. 35 %,
mask your semi-transperant with this donut (e.g. make all black parts fully transparent)
use this masked image as overlay for your full coloured donut.
This will leave you with a partly faded donut following the same contours as the original.
I am sorry I don't have any masking-code at hand, but these steps would accomplish the desired result.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a TextView and I need to put a black border on the top of it.
The view is created in java, so I can't use the classic XML divider trick.
Many answers here suggest to put a black line as a background. I tried, but I found out that zooming in the view results in the line overflowing its content (in my application the views' textSizes are constantly changed by pinch zooming, so I can't know a definite width in advance.
So, my question is: is there a simple way to add a top border to a TextView which adapts to its size and which can be created from java without using XML?
Try Compound Drawables. They can be set by XML or in Code.
Use nine patch images for the Drawables or even Shape drawables and they should scale ok with the TextView.
I'm trying to make a 9 patch image to be a header of my application but it doesn't work.
This is the image:
As you can already imagine, I want only the middle (blank) part to be streched and nothing else. It works normally in eclipse screen preview but it stretches it as if it wasn't 9 patch when i run it on my device.
I've had problems like this before so I'm clearly doing something wrong with 9 patches, I looked up a lot of info and tutorials on 9 patches and I just don't seem to get it. Could someone give me a good explanation where exactly to put the black dots for it to work and why?
When you put those extra lines in an image, they work like this:
Top and Left extra lines define the vertical and horizontal pixels which will be stretchable (the intersection is called stretchable area).
Bottom and Right extra lines are optional and define the padding. In this case, the intersection is the region in which the content will be placed (the rest is the padding).
I recommend you to use the 9 Patch editor included with the Android sdk. It is called draw9patch and can be found at <android-sdk-root>/tools. You will be able to see a preview of your image with 9patch.
Links:
Draw 9-patch
NinePatch
2D Graphics - Nine Patch
I can't believe it, the next thing I tried after asking a question worked. The fact that I had TWO lines in the bottom was the problem. I just put a single line BETWEEN the images in the bottom and it worked.
Like this:
If anyone still gives me a good explanation for each of the four sides of the image (why and where should the dots be put), I will still accept that answer.
I am currently trying to use 9 patch pictures in my app.
The image is quite clear and work pretty well in the graphic tool provided with SDK:
Picture is like this:
and the tool seems to work fine:
Unfortunately, with such a simple layout, the rendering is bad on a device and the 9 patch does not work at all:
<TextView
android:id="#+id/platenumber"
android:background="#drawable/plate_fr"
android:layout_width="320dip"
android:layout_height="wrap_content" />
Any idea on what I am doing wrong?
EDIT:
My picture is named *.9.png
The black lines have to be totally black(RGB:#000000) and the transparent zone around black lines totally transparent.
The extention of your 9-patch image should end with .9.png or it will be taken as a normal image
Check if you have at least one black pixel on all four sides of your images.
Ok, I am going to building some custom tab icon images as explained in the following post. But I just need to know what size do I need to build my tab icons? I keep on guessing and then putting them in this demo and they get squashed or changed. What ratio in pixels do I need to create my tab icons so that they appear right?
SOLUTION:
I will give sandy the best answer, especially since he is the only answer at this point, and because I did eventually use a 9 patch image. But I tell you what, for someone who is new to the graphic editing game, 9 patch images were a pain in the butt to use. I eventually just download someone else 9 patch image then edited the image for what I needed. If you look at my other question here. You can see the image I use as the background behind example 1 and example 2 are 9 patch images. And that works great because everything looks perfect when you move it to landscape mode as well.
You need to create a 9 - patch image.. for more see here
Id like to have a button shaped like a cloud. A 9 patch might be unusable since every time I create large borders around my cloud image, I get warnings about "bad patches" in the 9 patch tool. Using 1px borders gives weird results too 1. When replacing my resource with the btn_default from api 4 I get expected results, ruling out xml issues.
Without using 9 patches, wrap_content seems to work no more, growing the image to 100% width regardless of content. The 9 patch used is shown below.
I wouldn't mind some distortion, as long as content does not overflow. What would be the best solution?
I am not allowed to post images yet, apparently. Please see
zip containing screenshots and 9patch
Nice question.
I think there is no way to use those images and you might need to change them, but I will leave you some tips or things I would try:
To avoid overflow you will need to define the fill area. You can try just adding a fill area but not a scale area. If this works, you will have the cloud image with the text inside it.
Remember that 9patches scale up and not down.
Here is a link with a very good explanation of how everything works.
If nothing worked so far I would ask the designer to create a new image resource with a stretchable area. For instance, having cloud shape just in the corners.