I am trying to add an animated spinner inside a EditText view to the right. And programmatically show/hide it.
I have created the animated spinner by introducing a linear interpolation rotation:
res/anim/rotate_forever.xml
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:interpolator="@anim/linear_interpolator"
android:duration="1200" />
res/layout/main.xml
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="6dip"
android:paddingLeft="6dip"
android:orientation="horizontal"
android:background="@drawable/header_gradient" >
<EditText android:id="@+id/search_text"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:singleLine="true"
android:focusable="true" />
<ImageView android:id="@+id/search_spinner"
android:gravity="center_vertical|right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/spinner_black"/>
</LinearLayout>
The way I trigger an animation is programmatically which works, I see the EditView on the left and the ImageView spinning on the right (because I have no idea otherwise)
ImageView searchSpinner = (ImageView) findViewById(R.id.search_spinner);
Animation spinnerAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_forever);
searchSpinner.startAnimation(spinnerAnimation);
My questions are this:
- How can I place the ImageView inside the EditText on the far right. So it will appear inside not outside. (I thought I can just place a android:drawableRight, but that didn't work.
- How can I
hide/show the ImageView (spinner), I
tried setting the View's
invisibility, by doing
searchSpinner.setVisibility(View.INVISIBLE);
but that didn't work.
Thanks, if you have any better ideas how to approach this, I am listening :)