收藏 分销(赏)

MARS-android视频教程代码-第二季第八集.doc

上传人:xrp****65 文档编号:7046830 上传时间:2024-12-25 格式:DOC 页数:5 大小:73.50KB
下载 相关 举报
MARS-android视频教程代码-第二季第八集.doc_第1页
第1页 / 共5页
MARS-android视频教程代码-第二季第八集.doc_第2页
第2页 / 共5页
点击查看更多>>
资源描述
MARS-Android 视频教程实例源代码 第二季第八集 AVD版本 Build SDK和Mini SDK Animations01 package mars.admations01;//当时建包时输错了字母 import android.os.Bundle; import android.app.Activity; import android.view.Menu; 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.ImageButton; public class MainActivity extends Activity { private Button scaleButton=null; private Button rotateButton=null; private Button alphaButton=null; private Button translateButton=null; private ImageButton imageButton=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); scaleButton=(Button)findViewById(R.id.scaleButtonId); scaleButton.setOnClickListener(new scaleButtonOnClickListener()); rotateButton=(Button)findViewById(R.id.rotateButtonId); rotateButton.setOnClickListener(new rotateButtonOnClickListener()); alphaButton=(Button)findViewById(R.id.alphaButtonId); alphaButton.setOnClickListener(new alphaButtonOnClickListener()); translateButton=(Button)findViewById(R.id.translateButtonId); translateButton.setOnClickListener(new translateButtonOnClickListener()); imageButton=(ImageButton)findViewById(R.id.imageViewId); } class scaleButtonOnClickListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub System.out.println("scaleButtonOnClick"); AnimationSet animationSet=new AnimationSet(true); ScaleAnimation scaleAnimation=new ScaleAnimation(1,0.1f,1,0.1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); animationSet.addAnimation(scaleAnimation); animationSet.setDuration(2000); //animationSet.setFillBefore(false); animationSet.setFillAfter(true); imageButton.setAnimation(animationSet); } } class rotateButtonOnClickListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub System.out.println("rotateButtonOnClick"); AnimationSet animationSet=new AnimationSet(true); RotateAnimation rotateAnimation=new RotateAnimation(0,360,Animation.RELATIVE_TO_PARENT,1f,Animation.RELATIVE_TO_PARENT,0F); rotateAnimation.setDuration(5000); animationSet.addAnimation(rotateAnimation); imageButton.setAnimation(animationSet); } } class alphaButtonOnClickListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub System.out.println("alphaButtonOnClick"); AnimationSet animationSet=new AnimationSet(true); AlphaAnimation alphaAnimation=new AlphaAnimation(1,0); alphaAnimation.setDuration(1000); animationSet.addAnimation(alphaAnimation); imageButton.setAnimation(animationSet); } } class translateButtonOnClickListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub System.out.println("translateButtonOnClick"); AnimationSet animationSet=new AnimationSet(true); TranslateAnimation translateAnimation=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,1f); translateAnimation.setDuration(1000); animationSet.addAnimation(translateAnimation); imageButton.setAnimation(animationSet); } ; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } Activity_main.xml <RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" tools:context=".MainActivity" /> <Button android:id="@+id/scaleButtonId" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="测试scale效果" /> <Button android:id="@+id/rotateButtonId" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@id/scaleButtonId" android:text="测试rotate效果" /> <Button android:id="@+id/alphaButtonId" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@id/rotateButtonId" android:text="测试alpha效果" /> <Button android:id="@+id/translateButtonId" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@id/alphaButtonId" android:text="测试translate效果" /> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageButton android:id="@+id/imageViewId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="100dp" android:src="@drawable/ic_launcher" /> </LinearLayout> </RelativeLayout>
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服