I get the following warnings when I initialize an object of type animation.
(The warnings are added as comments)
Animation bottomUp = AnimationUtils.loadAnimation(
android.content.Context, // warning: Expression expected
R.animator.bottom_up // warning: Expected resource of type anim
);
Here is a picture
Here is the code summary:
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
}
This is log cat after I try to compile
Here is where I use the erroneous code
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);
I cannot find the bug.
I created the correct folder and files. Here they are.
Here is where I got the animation code I am using.
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);
Tried to create an anim
folder. Got this message.