我正在做一个使用eclipse创建动画的android项目。 在MainActivity.java上 它编译器显示5个lint错误如下
- 图像无法解析或不是字段 -activity_main无法解析或不是字段 -translate无法解析或不是字段 -rotate无法解析或不是字段 -shape无法解析或不是字段
这里是我在MainActivity.java中的代码
package ahmed103.appdemo;
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.*;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity implements AnimationListener {
ImageView image;
Animation animation1;
Animation animation2;
Button rotate, translate;
Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.image);
rotate = (Button) findViewById(R.id.rotate);
translate = (Button) findViewById(R.id.translate);
image.setImageResource(R.drawable.shape);
animation1 = AnimationUtils.loadAnimation(this, R.anim.rotate);
animation2 = AnimationUtils.loadAnimation(this, R.anim.translate);
userInputHandler();
}
private void userInputHandler() {
rotate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
image.startAnimation(animation1);
}
});
translate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
image.startAnimation(animation2);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
image.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
image.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationStart(Animation animation) {
image.setVisibility(View.VISIBLE);
}
}
下面是我的activity_main.xml文件
<html>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DCDCDC"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="70dp"
android:minHeight="150dp"
android:minWidth="150dp" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TableRow>
<Button
android:id="@+id/rotate"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:text="@string/rotate_text" />
<Button
android:id="@+id/translate"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:text="@string/translate_text" />
</LinearLayout>
</html>
答案 0 :(得分:0)
删除以下导入
import android.R;
您还有导入
<html> and </html>// should be removed from xml
并使用
import ahmed103.appdemo.R;
作为<?xml version="1.0" encoding="utf-8"?>