2014-12-03 130 views
1
package com.example.graph;          

public class MainActivity extends Activity       
{ 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState);       
     setContentView(R.layout.activity_main);     

     GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[]{ 
       new GraphViewData(1, 2.0d) 
       , new GraphViewData(2, 1.5d) 
       , new GraphViewData(3, 2.5d) 
       , new GraphViewData(4, 1.0d) 
      }); 

     GraphView graphView = new BarGraphView(MainActivity.this,"GraphViewDemo"); 
     graphView.addSeries(exampleSeries); 
     graphView.setBackgroundColor(getResources().getColor(android.R.color.holo_green_light)); 
     graphView.setBackgroundColor(Color.argb(50, 50, 0, 200));   
    } 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 
} 
+0

你實際上想要在你的graphView中添加什麼? – vembutech 2014-12-03 14:06:52

+0

我只想在圖形視圖或圖形表格後面顯示圖像 – nirmalnk 2014-12-05 16:06:14

回答

0

您可以通過設置graphView.setBackground財產graphview使用圖像爲背景,而Android會抱怨,如果你的最低API小於16

int imageResource = getResources().getIdentifier("@drawable/output_background", null, getPackageName()); 
Drawable graph_background = getResources().getDrawable(imageResource); 
graphView.setBackground(graph_background); 
0

另一種選擇是將圖形堆疊在ImageView的頂部。因此,如果您將GraphView添加到FrameLayout,請讓FrameLayout包含顯示圖像的ImageView。