2015-10-06 18 views
0

我是Android新手。我已創建條形圖使用此Link。但是當我運行我的模擬器。它給出了非常小的圖表。如何在Android中使用MPAAndroid設置圖表大小

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/mainLayout" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

</RelativeLayout> 

錯誤快照:Link 感謝您的幫助提前

+1

更新快照以及鏈接 – Siboo

回答

1

您使用的是相對佈局來存儲您的圖表?您可以嘗試將主容器的參數設置爲fill_parent,並將圖表的參數設置爲固定或fill_parent

我爲此使用了一個FrameLayout,但是這個具有類似參數的RelativeLayout也適用。

這個工作對我來說:

<FrameLayout 
       android:id="@+id/fl" 
       android:layout_width="fill_parent" 
       android:layout_height="210dp"> 

       <com.github.mikephil.charting.charts.BarChart 
        android:id="@+id/cl" 
        android:layout_width="0dp" 
        android:layout_height="200dp" /> 
</FrameLayout> 

在這個例子中圖表的高度是固定的,寬屏幕的寬度。

+0

因爲我使用的RelativeLayout將與類全局變量名稱類似:private RelativeLayout mainLayout;所以你的代碼dosent爲我工作。 – Siboo

+0

然後用相對替換框架。這些參數很重要。它將以這種方式工作。 – Virthuss

+0

它不工作親愛的。我的佈局是正確的,但只有圖表的問題會出現在很小的尺寸上。即使我也嘗試設置大小。但沒有工作 – Siboo

0

首先感謝@Virthuss的幫助。我在活動課上創建了一個框架佈局;

private FrameLayout mainLayout; 
mainLayout = (FrameLayout) findViewById(R.id.mainLayout); 

and on XML side。所謂的框架佈局像

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/mainLayout" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
</FrameLayout> 

感謝您的幫助再次了很多。

相關問題