不会出现 ScrollView 中的 XYPlot(AndroidPlot 库) [英] XYPlot (AndroidPlot library) in ScrollView does not appear
问题描述
我正在尝试放置 XYPlot
(来自 AndroidPlot 库 http://androidplot.com/) 在 ScrollView
容器中,因为这个 Activity 中会有更多的东西.不幸的是,我得到的只是空白,图表应该出现在那里(当我删除 ScrollView
时,它会正确显示).
我的布局xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin" 工具:context=".MainActivity"><滚动视图android:layout_width="match_parent"android:layout_height="wrap_content"android:fillViewport="true"><线性布局android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=垂直"><com.androidplot.xy.XYPlotandroid:id="@+id/mySimpleXYPlot"android:layout_width="match_parent"android:layout_height="wrap_content"androidPlot.title="一个简单的 XY 图"androidPlot.domainLabel="域"androidPlot.rangeLabel="范围"androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"androidPlot.graphWidget.marginTop="20dp"androidPlot.graphWidget.marginLeft="15dp"androidPlot.graphWidget.marginBottom="30dp"androidPlot.graphWidget.marginRight="10dp"androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"androidPlot.legendWidget.heightMetric.value="25dp"androidPlot.legendWidget.positionMetrics.anchor="right_bottom"androidPlot.graphWidget.gridLinePaint.color="#000000"/></LinearLayout></ScrollView>
我的onCreate()
方法:
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);Number[] series1Numbers = {1, 8, 5, 2, 7, 4};XYSeries series1 = 新的 SimpleXYSeries(Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");LineAndPointFormatter series1Format = new LineAndPointFormatter();series1Format.setPointLabelFormatter(new PointLabelFormatter());series1Format.configure(getApplicationContext(),R.xml.line_point_formatter_with_plf1);plot.addSeries(series1, series1Format);plot.setTicksPerRangeLabel(3);plot.getGraphWidget().setDomainLabelOrientation(-45);}
这是快速入门教程中的一个示例,略有删节.我已经检查了这个答案:Androidplot - X 轴标签被切断
当我将布局更改为:
<线性布局android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=垂直"><com.androidplot.xy.XYPlotandroid:id="@+id/mySimpleXYPlot"android:layout_width="match_parent"android:layout_height="match_parent" .../>
并添加几个 TextView
小部件,图表出现,但我无法滚动查看它们.最后,当我添加更多 TextView
小部件(像很多)时,图表不会再次出现,但我可以看到所有 TextView
小部件并滚动查看所有这些小部件.
有人可以帮忙吗?
我遇到了类似的问题.痛苦的部分是意识到这个问题实际上结合了两个独立的问题.
1.) 布局定义在为 XYPlot 定义布局时,而不是 android:layout_height="match_parent"
定义您需要的 dp 值(类似于 android:layout_height="200dp"
)>
2.) 硬件加速在检查 logcat 时,我注意到以下输出
<块引用>W/View:视图太大而无法放入绘图缓存,需要 10368000 字节,只有 8294400 可用
快速搜索使我这个stackoverflow 主题.所以基本上我将 android:hardwareAccelerated="false"
添加到 AndroidManifest.xml 文件中的 Activity.之后它起作用了,但速度慢得要命.我最终将 androidplot.renderMode="use_background_thread"
添加到 XYPlot 布局定义中,这些更改对我有用.
希望这会有所帮助.
I am trying to put XYPlot
(from AndroidPlot library http://androidplot.com/) in ScrollView
container, because there will be more stuff in this Activity. Unfortunately all I am getting back is blank space, where the chart should appear (when I remove ScrollView
it appears properly).
My layout xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.androidplot.xy.XYPlot
android:id="@+id/mySimpleXYPlot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
androidPlot.title="A Simple XY Plot"
androidPlot.domainLabel="Domain"
androidPlot.rangeLabel="Range"
androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"
androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"
androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
androidPlot.graphWidget.marginTop="20dp"
androidPlot.graphWidget.marginLeft="15dp"
androidPlot.graphWidget.marginBottom="30dp"
androidPlot.graphWidget.marginRight="10dp"
androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"
androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"
androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
androidPlot.legendWidget.heightMetric.value="25dp"
androidPlot.legendWidget.positionMetrics.anchor="right_bottom"
androidPlot.graphWidget.gridLinePaint.color="#000000"/>
</LinearLayout>
</ScrollView>
My onCreate()
method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
Number[] series1Numbers = {1, 8, 5, 2, 7, 4};
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
LineAndPointFormatter series1Format = new LineAndPointFormatter();
series1Format.setPointLabelFormatter(new PointLabelFormatter());
series1Format.configure(getApplicationContext(),
R.xml.line_point_formatter_with_plf1);
plot.addSeries(series1, series1Format);
plot.setTicksPerRangeLabel(3);
plot.getGraphWidget().setDomainLabelOrientation(-45);
}
It is an example from QuickStart Tutorial, slightly truncated. I have already checked this answer: Androidplot - X-Axis labels cut off
When I change layout to:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.androidplot.xy.XYPlot
android:id="@+id/mySimpleXYPlot"
android:layout_width="match_parent"
android:layout_height="match_parent" .../>
and add several TextView
widgets, the chart appears, but I can't scroll to see them. Finally, when I add more TextView
widgets (like a lot), chart doesn't appear again, but I can see all TextView
widgets and scroll to see all of them.
Can anyone help?
I had a somewhat similar problem. The painful part was to realise that this issue actually combines 2 separate problems.
1.) Layout definition
When defining the layout for the XYPlot, instead of android:layout_height="match_parent"
define the dp value you need ( something like android:layout_height="200dp"
)
2.) Hardware acceleration While checking the logcat, I noticed the following output
W/View﹕ View too large to fit into drawing cache, needs 10368000 bytes, only 8294400 available
A quick search led me to this stackoverflow topic. So basically I added android:hardwareAccelerated="false"
to the Activity in the AndroidManifest.xml file. After that it worked, but was slow as hell. I ended up with adding androidplot.renderMode="use_background_thread"
to the XYPlot layout definition and these changes did the trick for me.
Hopefully this will help.
这篇关于不会出现 ScrollView 中的 XYPlot(AndroidPlot 库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!