LinearLayout achartengine Chart not displaying in ScrollView

别来无恙 提交于 2019-12-04 12:11:40

问题


I'm trying to create an achartengine chart within a scrollview but it won't display! It just shows a black screen, but doesn't crash or anything. The thing is if I just change my tag to the chart displays just fine. And in my Java code I do have renderer.setInScroll(true); for the charts renderer. Is this an issue with my xml?

Here is my xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

    <LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="vertical" >

        <LinearLayout
        android:id="@+id/trendchart"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" />
    </LinearLayout>

</ScrollView>

(Currently the only thing in the ScrollView is the chart I plan to add more elements to make scrolling necessary, I just want it to display first)

Also I have tried to display it both with and without the wrapping linearlayout and it is the same result.


回答1:


Under the scrollview you have to insert

android:fillViewport="true"



回答2:


You will also have to do the following call, otherwise there will be display issues:

renderer.setInScroll(true);



回答3:


Other solution is to give a size for your LinearLayout @+id/trendchart:

for example:

<LinearLayout
        android:id="@+id/trendchart"
        android:layout_width="fill_parent"
        android:layout_height="180dp"
        android:orientation="vertical" />
    </LinearLayout>

works fine for me.




回答4:


I've tried the accepted answers but none of them work for me. I solved my problem by adding

chartView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 500));

But don't use
chartView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
because for some reason it still not displaying the chart. Hope that will help someone



来源:https://stackoverflow.com/questions/11617727/linearlayout-achartengine-chart-not-displaying-in-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!