2016-04-10 126 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>