2019独角兽企业重金招聘Python工程师标准>>>
<RelativeLayout xmlns:android=""xmlns:tools=""android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity" ><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:text="Button" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button1"android:layout_alignLeft="@+id/button1"android:layout_marginBottom="20dp"android:text="Button" /><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button2"android:layout_alignLeft="@+id/button2"android:layout_marginBottom="16dp"android:text="Button" /><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button3"android:layout_alignRight="@+id/button3"android:layout_marginBottom="38dp"android:text="Button" /><ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button4"android:layout_alignParentTop="true"android:layout_marginTop="26dp"android:src="@drawable/ic_launcher" />
</RelativeLayout>
这是布局文件
package ve;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {private Button alphaBut;//淡静淡出private ImageView imageView;private Button rotateBut;//旋转private Button scaleBut;//缩小也可以放大private Button tranBut;//移动@Overrideprotected void onCreate(Bundle savedInstanceState) {Create(savedInstanceState);setContentView(R.layout.activity_main);alphaBut=(Button) findViewById(R.id.button1);rotateBut=(Button) findViewById(R.id.button2);scaleBut=(Button) findViewById(R.id.button3);tranBut=(Button) findViewById(R.id.button4);imageView=(ImageView) findViewById(R.id.imageView1);alphaBut.setOnClickListener(new AlphaButoon());rotateBut.setOnClickListener(new RotateButoon());scaleBut.setOnClickListener(new ScaleButoon());tranBut.setOnClickListener(new TranButoon());}class TranButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);Animation animation=new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);animation.setDuration(2000);animationSet.addAnimation(animation);imageView.startAnimation(animationSet);tranBut.startAnimation(animationSet);}}class ScaleButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);Animation animation=new ScaleAnimation(1, 0.5f, 1, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);animation.setDuration(2000);animationSet.addAnimation(animation);imageView.startAnimation(animationSet);scaleBut.startAnimation(animationSet);}}class AlphaButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);Animation animation=new AlphaAnimation(0, 1);animation.setDuration(2000);animationSet.addAnimation(animation);imageView.startAnimation(animationSet);alphaBut.startAnimation(animationSet);}}class RotateButoon implements OnClickListener{@Overridepublic void onClick(View arg0) {AnimationSet animationSet=new AnimationSet(true);//0-360从那个角度转到那个角度,X轴的参考值,0,5f百分之50,Y轴的参考值,0,5f百分之50Animation rotate=new RotateAnimation(0, 360,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT,0.5f);Animation alpha=new AlphaAnimation(0, 1);rotate.setDuration(2000);animationSet.addAnimation(rotate);alpha.setDuration(100);animationSet.addAnimation(alpha);imageView.startAnimation(animationSet);rotateBut.startAnimation(animationSet);}}
}
主函数
转载于:
本文发布于:2024-01-29 11:33:53,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170649923714980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |