Let's say I have an Activity containing a ChartView (blue rectangle)
Now, I want to place another View on top of it that will stretch from the X-axis all the way to the top of ChartView.
I tried to do that by setting the margin-bottom equal to the height of the X-axis (red area), but I don't know how to get its height
How can I achieve this effect? Is there a way to get X-axis height in Android MP Chart? Or maybe there is a walkaround that will have a similar result?
Desirable outcome (the gray area is a view placed on top of the chart):
chart.getXAxis().mLabelHeight returns the height of x-Axis by pixel.
You can get it after OnGlobalLayoutListener, because it is calculated after x-Axis is drawn.
----------Updated Jun 22nd
another way is to use "getHeight() - mViewPortHandler.contentBottom()", but mViewPortHandler is protected, so an extended chart is necessary to provide access to mViewPortHandler
Related
I am new to android animation and i've been playing with animation in android.
But one thing i just don't get it?
how to set position in tag.
My question is what 50%p means?
Suppose I have a button at some place 1/3 of the top. now i want to move it to bottom of the layout.then move to left bottom then at the center of the layout.
the doc says
Float or percentage. Starting X/Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").
once see this doc. This will help you to solve your issue.
In my application I have a requirement to animate an image (this image view has an arrow set as source).
I am unable to figure this out how I can achieve this.To solve this i got x and y coordinates of second view that is rectangle after getting coordintes i am setting
scaleX() of image view that is purple line but I am not geeting desire out put because it stretches to the whole screen along x-axis
here is the code what i tried is
int x = (int) imageView.getX();
imageView2.setScaleX(x);
here imageview is rectangular box and imageview 2 is the purple line
Why you dont try with scenes? It's exactly what you need.
http://developer.android.com/training/transitions/scenes.html
I think you are getting the correct output when using the above code. Scale is defined against initial dimensions. And you would need to use something like this
dist = box.getX() - circle.getX()
and your scale would be
imageView2.setScale(dist/distInitial)
where distInitial you compute it at creation time using the dist formula.
You might need to change the position because it is scaled around the center of it (i.e. a smaller scale shrink margins to center of image)
You might want to perform this operations using a Canvas. It might be more efficient.
I'm working with MPAndroidChart and I'm really enjoying it since it's really well done.
But I've got a problem that I haven't been able to resolve in a few hours. I've got a seekbar under the three charts (as you can see from the screenshots below) and I'd like to align it with the X-axis, skipping the space occupied by the Y-axis' labels on the left and the padding that gets added on the right.
Have you got any suggestion on how to achieve my goal? Is there a way of knowing the labels' width and the charts' extra-padding? Or, better, can I get the X-axis width?
Thanks in advance! Bye!
Update to the latest version of the library if you have not already.
Then, just remove all offsets from the chart. It's in the documentation.
Call:
chart.setViewPortOffsets(0f, 0f, 0f, 0f);
This will remove all padding / margin / offset from the chart, making the actual content of the chart (the data) being the next thing to your screen edge.
I'm using a fill to color the area below my chart, and I want the graph to take up the entire view, so I'm setting zero margin on the right and left in my renderer.
mRenderer.setMargins(new int[]{20, 0, 20, 0});
Graph renders great; uses all horizontal space and doesn't look wonky like it does without fill extending to right or left margins when they're set to > 0 values.
I'm also using custom text labels, aligned center, and I'm getting the outer two labels clipped; setting padding on x labels amplifies the problem by pushing labels off view.
Is there a way I can fit all the x labels in without the truncation, and without having to use margins? I can fit them all using margins, but then it just looks funky using the fill below.
Ideally, I guess there'd be some way to set alignment on each text label individually; probably asking for a lot. Or, a means to specify whether it should fit x labels when using custom text labels, such that it would align right on the first, and align left on the last.
Thanks
I'm using achartengine. I don't know how to align the labels' text with their axis. On some screens, the text is centered with the axis; on other screens, they're on the bottom or on the top of the axis.
Is there a way to globally put them in the center of the axis?
I think you can use the following:
mRenderer.setYLabelsAlign(Align.LEFT, 0)
If you want to set the alignment on the right side of the grid, just set Align.LEFT, which means they are align on the left.
Reading these two threads might clear it more: Android AChartEngine - Unable to change textColor of Y-Axis Labels and AChartEngine : Align Y-Axis Labels on right side of Axis itself
Hope it helps.