java – 如何在android编码中的ImageView上写文本?

嗨,我一直试图在 Imageview上写数字. N个问题的图片.如果用户输入的答案是正确的,那么它应该显示带有带有刻度标记图像的问号,否则带有错误标记图像的问号.我需要在图像上写下问号.
这个例子: http://hotelreservbyvic.comli.com/whatineed.jpg我的代码在这里
LinearLayout l_layout = (LinearLayout) findViewById(R.id.linear_view_report);
    LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,1.0f);
    ImageView[] imgview=new ImageView[questions.length];
    for(int i=0;i<no_of_questions;i++)
    {
                if(userEnteredAnswers[i]==correct_answer[i]){           
                    Bitmap bm=BitmapFactory.decodeResource(getResources(),R.drawable.correct);
                    Canvas canvas = new Canvas(bm);
                    Paint paint = new Paint(); 
                    paint.setColor(Color.BLACK); 
                    paint.setTextSize(10); 
                    canvas.drawText(i,5,paint);

                    imgview[i]=new ImageView(this);
                    imgview[i].setimageDrawable(new BitmapDrawable(bm));
                    l_layout.addView(imgview[i]);
                }
                else {          
                    Bitmap bm=BitmapFactory.decodeResource(getResources(),R.drawable.wrong);
                    Canvas canvas = new Canvas(bm);
                    Paint paint = new Paint(); 
                    paint.setColor(Color.BLACK); 
                    paint.setTextSize(10); 
                    canvas.drawText(i,paint);

                    imgview[i]=new ImageView(this);
                    imgview[i].setimageDrawable(new BitmapDrawable(bm));
                    l_layout.addView(imgview[i]);
                }       
            }

我得到这个警告:

The constructor BitmapDrawable(Bitmap) is deprecated

运行时没有图像显示.
我究竟做错了什么?

解决方法

我相信最简单的解决方法,而不会覆盖任何东西,就是拥有一个TextView并设置一个可绘制资源的背景.

例如:

TextView t = (TextView)findViewById(R.id.my_text_view);
// setting gravity to "center"
t.setGravity(Gravity.CENTER);
t.setBackgroundResource(R.drawable.my_drawable);
t.setText("FOO");

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...