Android的图标错误 [英] Android icon error

查看:573
本文介绍了Android的图标错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个教程网站,因为我想学习它复制此code。但我在

得到一个错误

 包com.android.test;
进口android.R;
进口android.app.Activity;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.graphics.Matrix;
进口android.graphics.drawable.BitmapDrawable;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.ArrayAdapter;
进口android.widget.ImageView;
进口android.widget.SeekBar;
进口android.widget.Spinner;
进口android.view.ViewGroup.LayoutParams;
进口android.widget.LinearLayout;
进口android.widget.ImageView.ScaleType;
公共类旋转延伸活动{
     @覆盖
     公共无效的onCreate(捆绑savedInstanceState){
         super.onCreate(savedInstanceState);
         LinearLayout中的LinearLayout =新的LinearLayout(本);   位图位图= BitmapFactory.de codeResource(getResources(),R.drawable.icon);

在最后一行,我得到其中.icon写入错误。它说,图标不能得到解决,或者不是一个领域。


  

INT宽度= bitmap.getWidth();
         INT高度= bitmap.getHeight();

 矩阵矩阵=新的Matrix();
   matrix.postRotate(90);   位图rotatedBitmap = Bitmap.createBitmap(位图,0,0,


  
  

宽度,
           高度,矩阵,真);
         BitmapDrawable BMD =新BitmapDrawable(rotatedBitmap);

  ImageView的ImageView的=新ImageView的(本);
   imageView.setImageDrawable(BMD);
   imageView.setScaleType(ScaleType.CENTER);   linearLayout.addView(ImageView的,新LinearLayout.LayoutParams(
     LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
   的setContentView(LinearLayout中);
     }
 }



解决方案

在你的导入语句,你有

 进口android.R;

这意味着它会看起来在 android.R.drawable.icon ,rathern比 R.drawable.icon android.R 包含ID来从SDK的全部资产。要访问您自己的资产,您需要删除using语句,或手动编写 com.your.package.name.R.drawable.icon

I copied this code from a tutorial site because I am trying to learn it. But I am getting an error at

package com.android.test;
import android.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
public class Rotate extends Activity {
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         LinearLayout linearLayout = new LinearLayout(this);

   Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);

On this last line, I get an error where ".icon" is written. It says, "icon cannot be resolved or is not a field."

int width = bitmap.getWidth(); int height = bitmap.getHeight();

   Matrix matrix = new Matrix();
   matrix.postRotate(90);

   Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0,

width, height, matrix, true); BitmapDrawable bmd = new BitmapDrawable(rotatedBitmap);

   ImageView imageView = new ImageView(this);
   imageView.setImageDrawable(bmd);
   imageView.setScaleType(ScaleType.CENTER);

   linearLayout.addView(imageView, new LinearLayout.LayoutParams(
     LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
   setContentView(linearLayout);
     }
 }

解决方案

In your import statements, you have

import android.R;

That means it'll look in for android.R.drawable.icon, rathern than R.drawable.icon. android.R contains the IDs to all the assets from the SDK. To access your own assets, you need to remove the using statement, or manually write com.your.package.name.R.drawable.icon

这篇关于Android的图标错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆