热门排行
简介
代码介绍:
主要知识点:
1/ 全屏(可以通过XML文件进行描述,也可以通过代码进行控制):
styel.XML:
[code]
<style name="style_Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
[/code]
Java Code:
[code]
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
[/code]
2/ 感应器运用
实现SensorListener接口
[code]
public class compass extends Activity implements SensorListener {
private SensorManager sm = null;
@Override
public void onStart() {
Log.e(TAG, "Compass: onStart");
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
....
[/code]
接收事件消息
[code]
public void onSensorChanged(int sensor, float[] values) {
synchronized (this) {
if (sensor == SensorManager.SENSOR_ORIENTATION) {
Log.d(TAG, "onSensorChanged: " + sensor + ", x: " + values[0]
+ ", y: " + values[1] + ", z: " + values[2]);
//... 下面就是对方位数据的处理...
}
}
}
public void onAccuracyChanged(int sensor, int accuracy) {
Log.d(TAG, "onAccuracyChanged: " + sensor + ", accuracy: " + accuracy);
}
[/code]
3/ 动画效果(JAVA Code实现)
a.渐现渐隐
[code]
// 定义变量
private AlphaAnimation myAnimation_Alpha;
// 设置变量
myAnimation_Alpha=new AlphaAnimation(1.0f, 0.1f);
myAnimation_Alpha.setDuration(3000);
myAnimation_Alpha.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
[/code]
b.旋转效果/* 用于指南针罗盘旋转 */
[code]
// 定义变量
private RotateAnimation myAni = null;
// 设置变量
myAni = new RotateAnimation(DegressQuondam, fDegress,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
myAni.setDuration(300);
myAni.setFillAfter(true); /* 为实现指南针效果,设置旋转后不还原原图 */
ImgCompass.startAnimation(myAni);
[/code]