2016-04-10 127 views
1

(这个问题也适用于滚动型)MPAndroidChart内Horizo​​ntalScrollView

我需要放置LineChartHorizontalScrollView。除非是最后一个解决方案,否则我不希望在图表内滚动(意味着图表会呈现滚动本身,并且在多次测试之后,这相当滞后)。

图书馆是MPAndroidChart

基于this post on Telerik它不应该是复杂的。

不幸的是,我似乎无法达到目标结果。

这是我的XML代码:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.github.mikephil.charting.charts.LineChart 
     android:layout_width="2000dp" 
     android:layout_height="match_parent" 
     android:fillViewport="true" 
     android:id="@+id/chart"/> 

</HorizontalScrollView> 

真的没什么花哨。

Android Studio内部设计师显示了一个非常缩小的图表,我的手机也一样。

出了什么问题?

感谢您的帮助!

+0

您是否有解决方案? – Shadow

+0

@Shadow我还没有解决方案。图表缩小了。 – Mackovich

+0

你有没有找到这个解决方案? – TechValens

回答

1

使用的LinearLayout作为容器的折线图:

    <HorizontalScrollView 
        android:id="@+id/hsvChart" 
        android:layout_width="800dp" 
        android:layout_height="match_parent"> 
        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 
         <com.github.mikephil.charting.charts.LineChart 
          android:id="@+id/chart" 
          android:layout_width="600dp" 
          android:layout_height="match_parent" 
          android:layout_marginBottom="3dp" 
          android:layout_marginTop="3dp" /> 
        </LinearLayout> 
       </HorizontalScrollView> 

这将防止您的图表从萎缩

+0

如果我不想使用固定宽度,该怎么办?因为在我的应用程序有时x轴上的标签很小,可能会更改为40到50个字符或更多.. –

+0

我试图填充视图端口但它不工作 –

0

通过设置宽度匹配父的水平视图和自定义宽度为为我工作图表(见下面的代码):

<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="400dp" 
    android:fillViewport="true"> 

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

    <com.github.mikephil.charting.charts.BarChart 
     android:id="@+id/bar_chart" 
     android:layout_width="800dp" 
     android:layout_height="match_parent" 
     android:background="@color/colorWhite" 
     android:padding="10dp" /> 
</LinearLayout> 
</HorizontalScrollView>