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

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

概述嗨,我一直试图在 Imageview上写数字. N个问题的图片.如果用户输入的答案是正确的,那么它应该显示带有带有刻度标记图像的问号,否则带有错误标记图像的问号.我需要在图像上写下问号. 这个例子: http://hotelreservbyvic.comli.com/whatineed.jpg我的代码在这里: LinearLayout l_layout = (LinearLayout) findV 嗨,我一直试图在 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");
总结

以上是内存溢出为你收集整理的java – 如何在android编码中的ImageView上写文本?全部内容,希望文章能够帮你解决java – 如何在android编码中的ImageView上写文本?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1148520.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存