首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sensor.TYPE_ORIENTATION已弃用

Sensor.TYPE_ORIENTATION已弃用
EN

Stack Overflow用户
提问于 2016-06-21 06:35:23
回答 1查看 3K关注 0票数 3

我当时正在做一个指南针应用程序,我发现Sensor.TYPE_ORIENTATITON已经被弃用了,我不知道如何修复它。有没有可能得到一些帮助。以下是我的代码和我所做的工作。

代码语言:javascript
复制
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compass);

    // 
    // TextView that will tell the user what degree is he heading
    tvHeading = (TextView) findViewById(R.id.tvHeading);

    // initialize your android device sensor capabilities
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
}

@Override
protected void onResume() {
    super.onResume();

    // for the system's orientation sensor registered listeners
    mSensorManager.registerListener(this, **mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_GAME);**
}

@Override
protected void onPause() {
    super.onPause();

    // to stop the listener and save battery
    mSensorManager.unregisterListener(this);
}

@Override
public void onSensorChanged(SensorEvent event) {

    // get the angle around the z-axis rotated
    float degree = Math.round(event.values[0]);

    tvHeading.setText("Heading: " + Float.toString(degree) + " degrees");

    // create a rotation animation (reverse turn degree degrees)
    RotateAnimation ra = new RotateAnimation(
            currentDegree,
            -degree,
            Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF,
            0.5f);

    // how long the animation will take place
    ra.setDuration(210);

    // set the animation after the end of the reservation status
    ra.setFillAfter(true);

    // Start the animation
    image.startAnimation(ra);
    currentDegree = -degree;

}

这个想法是,在代码执行后,它必须根据指南针检测到的度数来旋转图像。

EN

回答 1

Stack Overflow用户

发布于 2021-02-08 21:52:26

你可以看看下面的答案

https://stackoverflow.com/a/17477963

(已经很长一段时间了,但可能会对某些人有所帮助)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37932903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档