I am trying to add an animated spinner inside the EditText view on the right. And show / hide it programmatically.
I created an animated counter by introducing linear rotation of the interpolation:
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 run the animation works programmatically, I see EditView on the left and ImageView on the right (because I have no idea about it)
ImageView searchSpinner = (ImageView) findViewById(R.id.search_spinner); Animation spinnerAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_forever); searchSpinner.startAnimation(spinnerAnimation);
My questions are as follows:
- How to place an ImageView inside an EditText at the far correctly. So he will appear inside not outside. (I thought I could just host android: drawableRight, but that doesn't work.
- How can I hide / show ImageView (spinner), I tried to set View invisibility by doing
searchSpinner.setVisibility(View.INVISIBLE); but it didn’t work.
Thank you, if you have any better ideas on how to approach this, I'm listening :)
source share