Java 在android graphview中添加背景图像
通过设置graphview.setBackground属性,您可以在graphview中使用图像作为背景,但是如果您的最小API小于16,Android会抱怨Java 在android graphview中添加背景图像,java,android,android-graphview,Java,Android,Android Graphview,通过设置graphview.setBackground属性,您可以在graphview中使用图像作为背景,但是如果您的最小API小于16,Android会抱怨 package com.example.graph; public class MainActivity extends Activity { protected void onCreate(Bundle s
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;
}
}
另一个选项是将图形堆叠在ImageView的顶部。因此,如果要将GraphView添加到FrameLayout,请使该FrameLayout已经包含显示图像的ImageView 你到底想在图形视图中添加什么?我只想在图形视图或图形表后面添加一个图像
int imageResource = getResources().getIdentifier("@drawable/output_background", null, getPackageName());
Drawable graph_background = getResources().getDrawable(imageResource);
graphView.setBackground(graph_background);