Vig*_*ala 12 java android imageview bitmapfactory
嗨,我一直在尝试在Imageview上编写Numbers.N个问题的图像.如果用户输入的答案是正确的,那么它应该显示带有刻度标记图像的问题编号,否则带有错误标记图像的问题编号.我需要在图像上写下问号.我的代码在这里:
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, 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, 5, 5, paint);
imgview[i]=new ImageView(this);
imgview[i].setImageDrawable(new BitmapDrawable(bm));
l_layout.addView(imgview[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个警告:
The constructor BitmapDrawable(Bitmap) is deprecated
Run Code Online (Sandbox Code Playgroud)
图像未在运行时显示.我究竟做错了什么?
Men*_*ena 18
我认为最简单的解决方法是在没有覆盖任何内容的情况TextView下使用drawable资源来设置其背景.
例如:
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");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24468 次 |
| 最近记录: |