【问题标题】:add background image in a android graphview在 android graphview 中添加背景图像
【发布时间】:2014-12-03 13:58:03
【问题描述】:
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 中添加什么?
  • 我只想在图形视图或图形表后面放一张图片

标签: java android android-graphview


【解决方案1】:

您可以通过设置 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);

【讨论】:

    【解决方案2】:

    另一个选项是将图形堆叠在 ImageView 的顶部。因此,如果您要将 GraphView 添加到 FrameLayout,请让该 FrameLayout 已经包含一个显示您的图像的 ImageView。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 2018-06-26
      • 2022-01-13
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多