// 重画
invalidate();
}
}
}
3. 修改 AndroidManifest.xml ,使之如下:
< xml version = "1.0" encoding = "utf-8" >
< manifest xmlns:android = "http://schemas.android.com/apk/res/android"
package = "com.pat.gui"
android:versionCode = "1"
android:versionName = "1.0" >
< application android:icon = "@drawable/icon" android:label = "@string/app_name" >
< activity android:name = ".ScrollPicture"
android:label = "@string/app_name"
android:screenOrientation = "sensor"
android:configChanges = "orientation" >
< intent-filter >
< action android:name = "android.intent.action.MAIN" />
< category android:name = "android.intent.category.LAUNCHER" />
intent-filter >
activity >
application >
< uses-sdk android:minSdkVersion = "7" />
< uses-permission android:name = "android.permission.CHANGE_CONFIGURATION" />
manifest >
注意 AndroidManifest.xml 文件中, 3 行粗体字。其中的 android:screenOrientation="sensor" 表示,由手机的重力感应器来决定屏幕是以 landscape 或者 portrait 方式显示。
运行结果:
结果表明可以同时在水平和垂直方向移动图片。