安卓图标错误

发布于 2024-10-05 22:10:19 字数 1634 浏览 0 评论 0原文

我从教程网站复制了这段代码,因为我正在尝试学习它。但我在 最后一行出现错误

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);

,其中写入“.icon”时出现错误。它说:“图标无法解析或不是字段。”

int 宽度 = bitmap.getWidth(); int height = bitmap.getHeight();

 矩阵矩阵 = new Matrix();
   矩阵.postRotate(90);

   位图旋转Bitmap = Bitmap.createBitmap(位图, 0, 0,

宽度, 高度、矩阵、真实); 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(线性布局);
     }
 }

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);
     }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等你爱我 2024-10-12 22:10:19

在您的 import 语句中,

import android.R;

这意味着它将查找 android.R.drawable.icon,而不是 R.drawable.icon >。 android.R 包含 SDK 中所有资源的 ID。要访问自己的资源,需要去掉using语句,或者手动编写com.your.package.name.R.drawable.icon

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

大姐,你呐 2024-10-12 22:10:19

图标有时有效,有时无效。将其更改为“ic_launcher”。这一直有效。这是在“res/drawable-?dpi”下找到的文件名。
它是出现在 Android 设备上的图标。

像这样:
.setIcon(R.drawable.ic_launcher)

Icon some times works and some times it does not. Change it to 'ic_launcher'. This works all the time. This is the file name found under 'res/drawable-?dpi'.
It is the icon that appears on the android device.

Like this:
.setIcon(R.drawable.ic_launcher)

落日海湾 2024-10-12 22:10:19

这很可能是因为您的 /res/drawable 文件夹中没有名为 icon.png/icon.bmp/icon.jpg 的图像,

因此,将网站上可能存在的图像复制到该文件夹​​中,应该没问题。

This is very likely because you don't have a image in your /res/drawable folder called icon.png/icon.bmp/icon.jpg

So, copy the image probably on the site in to that folder and it should be fine.

爱的那么颓废 2024-10-12 22:10:19

您必须将名为 icon.png 的图像复制到 res/drawable 目录中。

You have to copy an image called icon.png into the res/drawable directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文