Android按钮动画,按钮文本除外

标签 android android-layout animation

我的 android 应用程序中有一个动画按钮。当动画开始时,按钮文本也会被动画化。但我不需要那个动画。有没有只保留按钮背景动画的解决方案。

抱歉我的英语不好。

这是我在 anim 文件夹中的动画 XML:

<?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>

这是我在布局文件夹中的按钮:

<?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>

这是我启动动画的 Activity :

 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);
            }

        }
    });
}

请帮帮我。

最佳答案

最简单的解决方案如下 删除按钮文本 添加 TextView 把它放在按钮上 按钮动画不会影响 TextView 两者都将单独处理,您的文本动画问题将得到解决

关于Android按钮动画,按钮文本除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20465632/

相关文章:

javascript - 如何使用 Cocos2D-JS 将变量保存到 Android?

java - 从附加的 OnPreDrawListener 对象中获取 ViewTreeObserver 对象

java - 如何删除 cardview 中不必要的顶部填充?

android - xml 布局中的自定义 View 不起作用

android - ConnectivityManager.NetworkCallback 未按预期工作

Android:ActionBar 自定义问题

javascript - AngularJS 和动画

ios - 导航到另一个 ViewController 时,UITableView 行有问题

c# - 如何使用 Thread.Sleep 为二叉树设置动画?

android - 在仪器测试中找不到 Room.inMemoryDatabaseBuilder()