在这点上Android 确实比J2ME 强大很多 手机游戏开发最痛苦的是什么?? 是游戏引擎的开发,但是工程师会把大部分时间浪费在对坐标上,如果写引擎的时候没有把自适应考虑周全后期会非常痛苦,现在手机屏幕分辨率是各式各样 内存大小也是各式各样 所以可见自适应屏幕算法有多么的重要。

package cn.m15.xys; import android.app.Activity;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Matrix;import android.graphics.Paint;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout; public class Image extends Activity {    ImageView imageView = null;     @Override    protected void onCreate(Bundle savedInstanceState) {        imageView = new ImageView(this);        setContentView(R.layout.image);        LinearLayout ll = (LinearLayout) findViewById(R.id.iamgeid);        ll.addView(imageView);        // 向左移动        Button botton0 = (Button) findViewById(R.id.buttonLeft);        botton0.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View arg0) {                imageView.setPosLeft();            }        });         // 向右移动        Button botton1 = (Button) findViewById(R.id.buttonRight);        botton1.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View arg0) {                imageView.setPosRight();            }        });        // 左旋转        Button botton2 = (Button) findViewById(R.id.buttonRotationLeft);        botton2.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View arg0) {                imageView.setRotationLeft();            }        });         // 右旋转        Button botton3 = (Button) findViewById(R.id.buttonRotationRight);        botton3.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View arg0) {                imageView.setRotationRight();            }        });         // 缩小        Button botton4 = (Button) findViewById(R.id.buttonNarrow);        botton4.setOnClickListener(new OnClickListener() {             @Override            public void onClick(View arg0) {                imageView.setNarrow();            }        });         // 放大        Button botton5 = (Button) findViewById(R.id.buttonEnlarge);        botton5.setOnClickListener(new OnClickListener() {             @Override            public void onClick(View arg0) {                imageView.setEnlarge();            }        });         super.onCreate(savedInstanceState);     }     class ImageView extends View {        Paint mPaint = null;        Bitmap bitMap = null;        Bitmap bitMapDisplay = null;        int m_posX = 120;        int m_posY = 50;        int m_bitMapWidth = 0;        int m_bitMapHeight = 0;        Matrix mMatrix = null;        float mAngle = 0.0f;        float mScale = 1f;//1为原图的大小         public ImageView(Context context) {            super(context);            mPaint = new Paint();            mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);            bitMap = BitmapFactory.decodeResource(this.getResources(),                    R.drawable.image);            bitMapDisplay = bitMap;            mMatrix = new Matrix();            // 获取图片宽高            m_bitMapWidth = bitMap.getWidth();            m_bitMapHeight = bitMap.getHeight();        }         // 向左移动        public void setPosLeft() {            m_posX -= 10;        }         // 向右移动        public void setPosRight() {            m_posX += 10;        }         // 向左旋转        public void setRotationLeft() {            mAngle--;            setAngle();        }         // 向右旋转        public void setRotationRight() {            mAngle++;            setAngle();        }         // 缩小图片        public void setNarrow() {            if (mScale > 0.5) {                mScale -= 0.1;                setScale();            }        }         // 放大图片        public void setEnlarge() {            if (mScale < 2) {                mScale += 0.1;                setScale();            }        }         // 设置缩放比例        public void setAngle() {            mMatrix.reset();            mMatrix.setRotate(mAngle);            bitMapDisplay = Bitmap.createBitmap(bitMap, 0, 0, m_bitMapWidth,                    m_bitMapHeight, mMatrix, true);        }         // 设置旋转比例        public void setScale() {            mMatrix.reset();            //float sx X轴缩放            //float sy Y轴缩放            mMatrix.postScale(mScale, mScale);            bitMapDisplay = Bitmap.createBitmap(bitMap, 0, 0, m_bitMapWidth,                    m_bitMapHeight, mMatrix, true);        }         @Override        protected void onDraw(Canvas canvas) {            super.onDraw(canvas);            canvas.drawBitmap(bitMapDisplay, m_posX, m_posY, mPaint);            invalidate();        }    }}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@+id/iamgeid"    androidrientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >        <Button android:id="@+id/buttonLeft"            android:layout_width="fill_parent" android:layout_height="wrap_content"            android:text="图片向左移动"            />        <Button android:id="@+id/buttonRight"            android:layout_width="fill_parent" android:layout_height="wrap_content"            android:text="图片向右移动"            />        <Button android:id="@+id/buttonRotationLeft"            android:layout_width="fill_parent" android:layout_height="wrap_content"            android:text="图片左旋转"            />        <Button android:id="@+id/buttonRotationRight"            android:layout_width="fill_parent" android:layout_height="wrap_content"            android:text="图片右旋转"            />        <Button android:id="@+id/buttonNarrow"            android:layout_width="fill_parent" android:layout_height="wrap_content"            android:text="图片缩小"            />        <Button android:id="@+id/buttonEnlarge"            android:layout_width="fill_parent" android:layout_height="wrap_content"            android:text="图片放大"            /></LinearLayout>

更多相关文章

  1. Android入门:查看服务器图片应用
  2. Android(安卓)8.1 关机充电动画(二)Uboot模式
  3. Android开发Error(建议收藏下来以备不时之需)android.os.Transacti
  4. Android(安卓)BaseAdapter应用
  5. android 生成二维码图片
  6. Android(安卓)开源项目推荐
  7. 个人android遇到的问题总结
  8. 设置背景图时防止图片拉伸的解决方法
  9. android 加载大图长图失真或者不显示。

随机推荐

  1. 如何使用jquery在表中选择一行?
  2. Webhoster插入了一个javascript,它会阻止
  3. jquery的$.alerts.alert怎么实现点击后跳
  4. 浏览器Bug在输入上显示时间文本
  5. 在执行ajax时显示加载图像
  6. 使用jQuery的dataTable插件和嵌套的Ajax
  7. 在使用javascript将信息输入到输入字段时
  8. JQuery Mobile 手机显示页面偏小
  9. 具有嵌套效果循环的jquery动画
  10. JQuery属性与样式――.val()和增加样式.a