java - 在 android graphview 中添加背景图像

标签 java android android-graphview

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;
    }
}

最佳答案

您可以通过设置 graphView.setBackground 属性在 graphview 中使用图像作为背景,但如果您的最低 API 小于 16,Android 会提示。

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

关于java - 在 android graphview 中添加背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27273570/

相关文章:

java - 解码二进制原始文件

java - 如何创建动态 IF 语句?反射?

java - 通过使用FileAppender如何清除以前的数据并写入新的数据?

android - YouTube android 应用程序如何选择视频编解码器?

java - 重新创建 fragment 后恢复 UI 状态

android - 如何在 Android 中使用 GraphView 重绘图表

java - 如何安装 JAVA 8 Debian 8

android - Appium 仅在 Cordova 应用程序上显示 NATIVE_APP 上下文

Android GraphView调整整数水平标签的位置

android - 如何在android中使用渐变颜色制作水平条形图