简体   繁体   English

有没有办法获得 MP Android BarChart 的 px/dp 的条宽?

[英]Is there a way I can get the Bar Width in px/dp's of an MP Android BarChart?

I want to create a "table" (which is build with a recycle view) below my chart.我想在图表下方创建一个“表格”(使用回收视图构建)。 But I want the RecycleView to have the same number of elements of my chart (In this case 7) Is there a way to get the column width of the Bar Chart so I can assign the same width to my Recycle View Cells?但我希望 RecycleView 具有相同数量的图表元素(在本例中为 7)有没有办法获取Bar Chart的列width ,以便我可以为我的回收视图单元格分配相同的宽度?

在此处输入图片说明

At the end (if it is posible) I want the two scroll to be synced.最后(如果可能的话)我希望两个滚动同步。

The bar width in pixels is the difference between the value bar width x position (wp) and the label starting position (xp):以像素为单位的条宽是条宽 x 位置 (wp) 与标签起始位置 (xp) 之间的差值:

        Transformer transformer = bChart.getTransformer(YAxis.AxisDependency.LEFT);
        float bw = (float) transformer.getPixelForValues(bChart.getBarData().getBarWidth(), 0).x;
        float xp = (float) transformer.getPixelForValues(0, 0).x;
        float barWidthInPixels = bw - xp;

As you can see from the javadoc, BarData#getBarWidth() returns a the bar width in chart values (not in pixels). 从javadoc可以看出, BarData#getBarWidth()以图表值(不是以像素为单位)返回条形宽度。

You can translate between chart values (x and y values on the chart) and pixel values (for the Android handset's screen) using a Transformer . 您可以使用Transformer在图表值(图表上的x和y值)和像素值(针对Android手机的屏幕)之间进行Transformer Something like the following: 类似于以下内容:

float barWidth = barData.getBarWidth();
Transformer transformer = mChart.getViewPortHandler().getTransformer(AxisDependency.LEFT);
MPPointD barDimensPoint = transformer.getPixelForValues(barWidth, 0);
float barWidthInPixels = (float) barDimensPoint.x;

It's essentially the opposite operation from this question where the requirement is to translate pixels into values on the chart. 它本质上是与这个问题相反的操作,其中要求是将像素转换为图表上的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android中px和dp之间的不一致 - Inconsistency between px and dp in android android:scaleType =“ center”不能满足我的要求:dp vs px如何工作? - android:scaleType=“center” doesn't do what I think it should: how does dp vs px work? 在 Android 应用程序中,我将所有 px 更改为 dp 和 sp。 现在打不开了。 怎么了? - In Android app,I changed all px to dp and sp. Now it is not opening. What is wrong? 当imageview的宽度使用dp单位时,Android属性动画不起作用 - Android property animations does not work when imageview's width uses dp units 在 Kotlin 中将 Dp 转换为 Px - 这种转换永远不会成功 - Convert Dp to Px in Kotlin - This cast can never succeed 为什么1dp在Android上同时表示3px和2px? - Why does 1dp mean 3px and 2px at the same time on Android? 在Android中,如何设置ListView项的高度和宽度? - In Android, how can I set a ListView item's height and width? 如何在MP Android BarChart中从Y轴删除值 - How to remove value from the Y axis in MP Android BarChart 如何获取屏幕的宽度和高度-Android - How can I get the width and Height of the screen -Android 没有文件扩展名的 MP3 文件如何在 Android 文件应用程序中播放,有什么方法可以在我的 MP3 播放器 Android 应用程序中播放这些文件? - How can MP3 files without a file extension play in the Android files app and is there any way I can play such files in my MP3 player Android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM