【发布时间】:2015-10-02 06:31:30
【问题描述】:
我在初始化动画类型的对象时收到以下警告。
(警告被添加为 cmets)
Animation bottomUp = AnimationUtils.loadAnimation(
android.content.Context, // warning: Expression expected
R.animator.bottom_up // warning: Expected resource of type anim
);
这是一张照片
这里是代码摘要:
public class MainActivity extends AppCompatActivity {
// Class variables go here
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set onclick listener
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// Animation Code
Animation bottomUp = AnimationUtils.loadAnimation(
android.content.Context, // warning: Expression expected
R.animator.bottom_up // warning: Expected resource of type
);
ViewGroup hiddenPanel = (ViewGroup)findViewById(R.id.hidden_panel);
hiddenPanel.startAnimation(bottomUp);
hiddenPanel.setVisibility(View.VISIBLE);
}
});
}
// Other stuff
}
这是我尝试编译后的日志猫
这是我使用错误代码的地方
public class MainActivity extends AppCompatActivity {
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Animation bottomUp = AnimationUtils.loadAnimation(
android.content.Context,
R.animator.bottom_up
);
ViewGroup hiddenPanel = (ViewGroup)findViewById(R.id.hidden_panel);
hiddenPanel.startAnimation(bottomUp);
hiddenPanel.setVisibility(View.VISIBLE);
我找不到错误。
我创建了正确的文件夹和文件。他们来了。
Here 是我得到我正在使用的动画代码的地方。
bottom_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="75%p"
android:toYDelta="0%p"
android:fillAfter="true"
android:duration="500"/>
</set>
bottom_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator"
android:duration="500" />
</set>
Java
Animation bottomUp = AnimationUtils.loadAnimation(getContext(),
R.anim.bottom_up);
ViewGroup hiddenPanel = (ViewGroup)findViewById(R.id.hidden_panel);
hiddenPanel.startAnimation(bottomUp);
hiddenPanel.setVisibility(View.VISIBLE);
试图创建一个anim 文件夹。收到这条消息。
【问题讨论】:
-
警告在哪里?而在代码的第一个摘录中,android.content.Context 是类,你应该提供一个实例
-
@IliiazAkhmedov 警告在对象初始化代码中作为 cmets 添加
标签: android