How to center domain label below bar in a bar chart? - android

Currently, each bar's domain label appears below the left hand side of each bar, as pictured here:
Is there a way to position labels below each bar's center ?

This should do the trick:
XYGraphWidget.LineLabelStyle style = plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM);
style.getPaint().setTextAlign(Paint.Align.CENTER);

I believe you are doing that on canvas.
You already know the width of the bar.
Measure the text size (width) to be displayed using
Measuring text height to be drawn on Canvas ( Android )
(barWidth/2 - textWidth/2) + barLeft should do, i think.

Related

MPAndroidChart - Horizontal bar chart - Justify label text to the left

I'm using MPAndroidChart to create a horizontal bar graph.
Is it possible to justify the label text from the left as opposed to the right?
Code:
mChart.getXAxis().setValueFormatter(new LabelValueFormatter(set1));
mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
mChart.getXAxis().setXOffset(100);
Setting the axis position to the TOP and reversing the offset worked:
mChart.getXAxis().setValueFormatter(new LabelValueFormatter(set1));
mChart.getXAxis().setPosition(XAxis.XAxisPosition.TOP);
mChart.getXAxis().setXOffset(-350);
you can set to draw the values above the bars by:
mChart.setDrawValueAboveBar(true);
the result is like this image.

Fill shape with text with two different color

I tried to achieve this but I am only able to achieve to fill object (shape).
My requirement is to change text color along with shape filling.
Shape can be filled with percentage like till
10% to 50% = Green
51% to 80% = Yellow
81% to 100% = Red
When Yellow color fills background of ":" in shape, it will change color to "White" which is previously "Yellow". Size of this shape is also dynamic.
What I tried and achieved?
I am able to fill shape with percentage but failed to change color when it reaches to edge of text.
I wrote a custom view. You get this double color effect using Path APIs. But for Android 1+ compatibility, you should use Region API and above Kitkat (19+) you can use just Path API.
Let's go through the concept of how to achieve this effect step by step:
There are three shapes we need to draw - Outline Rounded Stroke + Orange Progress Bar + the text itself
We draw the stroke as it is
But for the Progress bar, we need to remove the text that intersects with it and basically make the text intersection transparent. (DIFFERENCE)
Also for the Progress Bar, we have to show only the part of the rectangle that intersects with the outer rounded stroke path. (INTERSECTION)
And similarly, for the text, on the left side we basically chop off the parts that intersects with the progress bar. And we only show the right side of the text that is orange in color. (DIFFERENCE again)
If you are using API 19+, this is how the critical code snippet looks like:
croppedProgressPath.op(progressPath, textPath, Path.Op.DIFFERENCE);
croppedProgressPath.op(progressStrokePath, Path.Op.INTERSECT);
————————————
croppedTextPath.op(textPath, progressPath, Path.Op.DIFFERENCE);
Lines here and here.
I’ve written a Proof of Concept for this project called Diffre on Github. If you wanna test it out first, all the code is in this repo.

Progress Bar in Action Bar: Make width fill screenwidth

I have a progress bar in my action bar, which is set to indeterminate. As you can see in my screenshot my progress bar's width is not 100% of the screen width. it has a margin on both sides. I am using the support libraries and actionbar activity. Is i possible to make it's width to 100% screen width? If yes, how to do that?
what are you looking for is an image of progress bar with different padding ...
see this ... select an progress bar icon from clipart a set different padding for image ... you can see what is padding doing with an image on example at the botton of the page :) this will 100% help you ...

Issue with custom seek bar in Android

I am having problem with custom seek bar I am not getting same as i expect, I am using 2nd image as progress drawable and first as thumb, but when i use wrap content it is small and when i use fill parent it is repeating and the seek bar different from the 2nd image in the UI?
You should use Nine-path graphics. With this android will automatically resize your image based on borders you provide in graphics.
set maxHeight and minHeight of seekbar properties.
example:
maxHeight = 40dp
minHeight = 40dp

Android Custom EditText text alignment bottom

I created a custom drawable for the background of an EditText. I need the text to be left and bottom aligned. It renders fine on screen but the text is not aligned to the right nor the bottom of the drawable. I also tried gravity:bottom and tried setting the padding on top in hopes it would move it down. Is there anything else I can do?
The right and bottom lines define the content area.
The line you draw on the right spans the top half of your image. That's why the text won't align to the bottom.
You should draw a slightly longer line.
Check out the image used by default. (I changed it to blue here though).
This will give the same result you are having. The text won't be aligned to the bottom.
Now if I extend the right line to the bottom, I would obtain the below image.
This will give you the expected result.

Categories

Resources