My main objective for this is to get it to have a "button" that initially is dark and when pressed cycles through the animation of it lighting up in a clockwise direction like a progress bar. But I can't seem to get animationdrawable working at all.
I have my xml animation called squareanimation located in a drawable resource folder in the res directory
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="@drawable/square" android:duration="210" />
<item android:drawable="@drawable/square1" android:duration="210" />
</animation-list>
I have my ImageView in my Layout
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.soundboard.sounds.MainActivity"
android:background="@drawable/app_background">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Cowbell"
android:id="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:gravity="center"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageHost"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="beep"
android:id="@+id/beepButton"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/square" />
</TableLayout>
</RelativeLayout>
Then I have my activity
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
AnimationDrawable squareanimation;
Button beepButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beepButton = (Button) findViewById(R.id.beepButton);
ImageView square = (ImageView) findViewById(R.id.imageHost);
square.setBackgroundResource(R.drawable.squareanimation);
squareanimation = (AnimationDrawable) square.getBackground();
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if(squareanimation == null)beepButton.setText("Not working");
return true;
}
return super.onTouchEvent(event);
}
These are only snippets of my code
Everytime I run my program no matter how many times I clean or rebuild or whatever, the program won't change squareanimation from being null. And if I do run the squareanimation.start() method it crashes the program.
My images are all in PNG format at 128px * 128px if that changes anything at all. All my Images are stored in the drawable-hdpi folder.