【发布时间】:2017-03-09 03:56:50
【问题描述】:
我只想让我的图像按钮在应用程序启动时在第一个屏幕上执行缩放(反复小放大和缩小)动画,直到我按下它。那是因为这是应用程序的“主要”和最重要的按钮,我想引起用户的注意。我找到了一些教程,我已经走到了这一步:
MainScreen.java
package com.example.konarx.a11042016;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
public class MainScreen extends AppCompatActivity {
private Button btn;
final Animation scale; //ERROR - Variable 'scale' might not have been initialized//
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
final scale = AnimationUtils.loadAnimation(this, R.anim.gps_button_animation); //ERROR - Unknown class: 'scale'//
btn = (Button) findViewById(R.id.ImageButton); //ERROR - Unexpected cast to `Button`: layout tag was `ImageButton`//
btn.startAnimation(scale); //I just want to do the animation without clicking it. Is that going to work?//
}
public void InfoActivity(View view) {
Intent intent = new Intent(this, InfoActivity.class);
startActivity(intent);
}
}
gps_button_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<scale
android:fromXScale="1.0"
android:toXScale="3.0"
android:fromYScale="1.0"
android:toYScale="3.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:repeatCount="1"
android:repeatMode="reverse" />
</set>
main_activity.xlm 中的按钮 xml
<ImageButton
android:id="@+id/ImageButton"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/button_image"
android:layout_marginTop="15dp"
/>
请帮忙:(
ps:我是新手,这是我的第一个应用程序
【问题讨论】:
标签: java android xml animation button