2015-05-21 82 views
0

我想寫一個代碼來繪製在android layout.C使用aChartengine繪製圖形我成功地繪製了圖形,但我面臨的問題,以對齊圖形在某個ViewGroup內的佈局。如何在Android佈局中正確對齊aChartEngine圖表?

mycode的:

MainActivity.java

public class MainActivity extends ActionBarActivity { 

List<double[]> xValues; 
List<double[]> yValues; 
List<double[]> yValues1; 

GraphicalView view; 
MultipleTemperatureChart multiple; 
RelativeLayout rlt; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    xValues = new ArrayList<double[]>(); 
    yValues = new ArrayList<double[]>(); 
    yValues1 = new ArrayList<double[]>(); 

    rlt = (RelativeLayout) findViewById(R.id.rlt); 

    multiple = new MultipleTemperatureChart(this); 

    int[] data = {143,144,145,137,156,146,158,139,144,143}; 

    double[] doubTime = new double[data.length]; 
    double[] doubNote = new double[data.length]; 
    double[] doubZero = new double[data.length]; 

    for(int i=0;i<data.length;i++){ 

     doubTime[i] = index; 
     doubNote[i] = data[i]; 
     doubZero[i] = 0; 

     index++; 
    } 

    xValues.add(doubTime); 
    yValues.add(doubNote); 
    yValues1.add(doubZero);  


    view = multiple.execute(getApplicationContext(),xValues,yValues,yValues1); 
    view.setBackgroundColor(Color.YELLOW); 
    view.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 400)); 

    rlt.addView(view); 

} 


} 

activity_main.xml中

<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"> 


     <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="500dp" 
       android:orientation="vertical" 
       android:background="#33cc00" 
       android:id="@+id/rltParams"> 

      <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        android:id="@+id/rlt"/> 

      <View 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_below="@+id/rlt" 
        android:background="#cc4455" 
        android:id="@+id/view"/> 

    </RelativeLayout>   

enter image description here

所以這些是我的問題的代碼和屏幕截圖。我想繪製綠色RelativeLayout以及紅色視圖內的圖形需要低於圖形佈局。

請給我一些解決方案或技巧,以正確地在佈局中繪製圖形。

如果你想要把圖表的綠色佈局裏面試試這個

回答

0

<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"> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="500dp" 
    android:orientation="vertical" 
    android:background="#33cc00" 
    android:id="@+id/rltParams"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:id="@+id/rlt"/> 

<View 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"      
     android:background="#cc4455" 
     android:id="@+id/view"/> 

</RelativeLayout> 

只是刪除以下行:

android:layout_below="@+id/rlt" 

這是什麼紅色的景觀?


嘗試是這樣的: (要看到紅色查看你需要把一個高度佈局@ + ID/RLT內)。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="500dp" 
    android:orientation="vertical" 
    android:id="@+id/rltParams"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:background="#33cc00" 
     android:id="@+id/rlt"/> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#cc4455" 
     android:layout_below="@+id/rlt" 
     android:id="@+id/view"/> 

    </RelativeLayout> 
+0

謝謝,紅視部件視圖佈局具有色碼「#cc4455」,這是在顏色有紅,對不起,我到現在也沒解釋它正確 – MyCode

+0

沒有,總佈局紅色,所以,視圖佈局覆蓋整個屏幕 – MyCode