当前位置:  编程技术>移动开发
本页文章导读:
    ▪程序实现挪动+缩放        程序实现移动+缩放   准备一张名为picture的图片。     在main.xml中:   <LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fi.........
    ▪ 作图矩形(方法二、空心的)        绘制矩形(方法二、空心的)     在main.xml中:   <LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent">   <com.li..........
    ▪ 卡通片监听       动画监听   准备一张名为picture的图片。     在main.xml中:   <LinearLayout     android:id="@+id/group"     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     andro.........

[1]程序实现挪动+缩放
    来源: 互联网  发布时间: 2014-02-18
程序实现移动+缩放

 

准备一张名为picture的图片。

 

 

在main.xml中:

 

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="#000000"

    android:orientation="vertical"

    android:gravity="center_horizontal">

  <ImageView

      android:id="@+id/mlyw"

      android:layout_marginTop="8dp"

      android:layout_width="fill_parent"

      android:layout_height="wrap_content"

      android:src="/blog_article/@drawable/picture/index.html"/>

  <Button

      android:id="@+id/but"

      android:layout_width="100dp"

      android:layout_height="40dp"

      android:layout_marginTop="20dp"

      android:background="#3399ff"

      android:textColor="#ffffff"

      android:text="开始移动缩放"/>

</LinearLayout>

 

 

 

 

 

在MyAnimationDemo.java中:

 

package com.li.animation;

 

import android.os.Bundle;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.view.Menu;

import android.view.MenuItem;

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;

import android.support.v4.app.NavUtils;

 

@SuppressLint("ParserError")

public class MyAnimationDemo extends Activity {

  private ImageView mlyw = null;

  private Button but = null;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        super.setContentView(R.layout.main);

        this.mlyw = (ImageView)super.findViewById(R.id.mlyw);

        this.but = (Button)super.findViewById(R.id.but);

        this.but.setOnClickListener(new OnClickListenerImpl());

    }

    private class OnClickListenerImpl implements OnClickListener{

     public void onClick(View v) {

       AnimationSet set = new AnimationSet(true);

       TranslateAnimation tran = new TranslateAnimation(

            Animation.RELATIVE_TO_SELF,0.0f ,  // X轴开始位置

            Animation.RELATIVE_TO_SELF,0.5f ,  // X轴移动的结束位置

            Animation.RELATIVE_TO_SELF,0.0f ,  // Y轴开始位置

            Animation.RELATIVE_TO_SELF,1.5f ); // Y轴移动位置

       ScaleAnimation scale = new ScaleAnimation(1, 0.0f, 1, 0.0f,

            Animation.RELATIVE_TO_SELF, 0.5f,

            Animation.RELATIVE_TO_SELF, 0.5f);

       scale.setRepeatCount(2) ; //重复两次

       set.addAnimation(tran); // 增加动画

       set.addAnimation(scale); // 增加动画

       set.setDuration(5000); // 5秒完成动画

       MyAnimationDemo.this.mlyw.startAnimation(set); // 启动动画

     }

    }

}

 


    
[2] 作图矩形(方法二、空心的)
    来源: 互联网  发布时间: 2014-02-18
绘制矩形(方法二、空心的)



 

 

在main.xml中:

 

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent">

  <com.li.paintproject.MyView

      android:layout_width="fill_parent"

      android:layout_height="wrap_content"/>

</LinearLayout>

 

 

 

 

 

在MyPaintDemo.java中:

 

package com.li.paintproject;

 

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.MenuItem;

import android.support.v4.app.NavUtils;

 

public class MyPaintDemo extends Activity {

 

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

    }

}

 

 

 

 

在MyView.java中:

 

package com.li.paintproject;

 

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Paint.Style;

import android.graphics.Rect;

import android.util.AttributeSet;

import android.view.View;

 

public class MyView extends View {

 

  public MyView(Context context, AttributeSet attrs) {

     super(context, attrs);

  }

 

  @Override

  protected void onDraw(Canvas canvas) {

    canvas.drawColor(Color.BLACK) ;  // 画布为黑色

     Paint paint = new Paint() ;

     paint.setColor(Color.YELLOW) ; // 设置图形的颜色

     Rect rect = new Rect();   //定义矩形

     rect.set(120,50,360,200); //矩形左上角坐标(160,50),右下角坐标(360,200)

     paint.setStyle(Style.STROKE); //空心的

     canvas.drawRect(rect, paint);

  }

}

 


    
[3] 卡通片监听
    来源: 互联网  发布时间: 2014-02-18
动画监听



 

准备一张名为picture的图片。

 

 

在main.xml中:

 

<LinearLayout

    android:id="@+id/group"

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="#000000"

    android:orientation="vertical"

    android:gravity="center_horizontal">

  <ImageView

      android:id="@+id/mlyw"

      android:layout_marginTop="8dp"

      android:layout_width="fill_parent"

      android:layout_height="wrap_content"

      android:src="/blog_article/@drawable/picture/index.html"/>

</LinearLayout>

 

 

 

 

在MyAnimationDemo.java中:

 

package com.li.animation;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.ViewGroup;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

import android.view.animation.Animation.AnimationListener;

import android.view.animation.AnimationSet;

import android.view.animation.TranslateAnimation;

import android.widget.ImageView;

 

public class MyAnimationDemo extends Activity {

  private ImageView mlyw = null;

  private ViewGroup group = null ;

 

  @Override

  public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);

     super.setContentView(R.layout.main);

     this.mlyw = (ImageView) super.findViewById(R.id.mlyw);

     this.group = (ViewGroup) super.findViewById(R.id.group);

     AnimationSet set = new AnimationSet(true);

     TranslateAnimation tran = new TranslateAnimation(

         Animation.RELATIVE_TO_SELF,0.0f ,  // X轴开始位置

         Animation.RELATIVE_TO_SELF,0.5f ,  // X轴移动的结束位置

         Animation.RELATIVE_TO_SELF,0.0f ,  // Y轴开始位置

         Animation.RELATIVE_TO_SELF,1.5f ); // Y轴移动位置

     tran.setDuration(6000); // 3秒完成动画

     set.addAnimation(tran); // 增加动画

     set.setAnimationListener(new AnimationListenerImpl()) ;

     this.mlyw.startAnimation(set); // 启动动画

  }

 

  private class AnimationListenerImpl implements AnimationListener {

 

     public void onAnimationEnd(Animation animation) {

       MyAnimationDemo.this.group.removeView(MyAnimationDemo.this.mlyw) ;

     }

 

     public void onAnimationRepeat(Animation animation) {

      

     }

 

     public void onAnimationStart(Animation animation) {

       if(animation instanceof AnimationSet) {

         AnimationSet set = (AnimationSet) animation ;

         AlphaAnimation alpha = new AlphaAnimation(1, 0);

         alpha.setDuration(3000) ;

         set.addAnimation(alpha) ;

       }

     }

    

  }

}

 

 

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
软件工程/软件设计 iis7站长之家
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3