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 offWhen 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 definitionWhen 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 accelerationWhile checking the logcat, I noticed the following output W/View﹕ View too large to fit into drawing cache, needs 10368000 bytes, only 8294400 availableA 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 库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-23 05:12