Reputation: 743
I have an animated button in my android application. When the animation starts, also the button text is animated. But I do not need that animation. Is there any solution that keeps only the button background animation.
Sorry for my poor English.
Here is my animation XML in anim folder:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:startOffset="0"
android:repeatCount="infinite"
android:repeatMode="restart" />
</set>
Here is my button in layout folder:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/firstscreenimage" />
</RelativeLayout>
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp"
android:background="@drawable/animation0"
android:text="Start" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/relativeLayout1"
android:layout_marginRight="28dp"
android:layout_marginTop="26dp"
android:text="0.0km"
android:textSize="30dp" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<requestFocus />
</EditText>
</RelativeLayout>
And here is my activity that I started the animation:
public class Gps extends Activity {
TextView display;
Button start;
boolean doubleclick = false;
AnimationDrawable AppNameAnimation;
double currentLon = 0;
double currentLat = 0;
double lastLon = 0;
double lastLat = 0;
double distance;
LocationManager lm;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
display = (TextView) findViewById(R.id.textView1);
start = (Button) findViewById(R.id.button1);
final Animation animRotate = AnimationUtils.loadAnimation(this,
R.anim.anim_rotate);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!doubleclick) {
v.startAnimation(animRotate);
start.setText("stop");
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(lm.GPS_PROVIDER, 0, 0, Loclist);
Location loc = lm.getLastKnownLocation(lm.GPS_PROVIDER);
if (loc == null) {
display.setText("No GPS location found");
} else {
// set Current latitude and longitude
currentLon = loc.getLongitude();
currentLat = loc.getLatitude();
}
// Set the last latitude and longitude
lastLat = currentLat;
lastLon = currentLon;
doubleclick = true;
} else {
lm.removeUpdates(Loclist);
start.setText("start");
v.clearAnimation();
doubleclick = false;
Intent in = new Intent(Gps.this, NextActivity.class);
startActivity(in);
}
}
});
}
Please help me.
Upvotes: 1
Views: 1190
Reputation: 7023
The Simplest Solution for this is following Remove Button text Add Text View place it over button button animation won`t effect TextView both will be handled separately and your text animation problem will be solved
Upvotes: 2