根据方向提供不同的_功能_(不仅仅是布局)?

发布于 2024-12-05 03:45:49 字数 448 浏览 0 评论 0原文

我有一个监控应用程序,它以动画形式显示一组四个参数(例如,它使用温度计图形显示温度)。我还有一个屏幕,将所有四个参数值绘制在图表上。

我的要求是:

  1. 每当设备处于横向模式时,都应该显示图表。
  2. 每当设备返回纵向模式时,都应显示较早的动画屏幕。

我想知道是否可以根据方向提供不同的功能。我看到 2 个选项

  1. Override Activity.onConfigurationChanged() - 但然后呢?我现在可以执行 setContentView() 吗?或者,我可以启动另一个活动(在单独的仅限横向模式的活动中显示图表的活动)吗?
  2. 重写 Application.onConfigurationChanged() 方法。但坦率地说,我不知道如何继续下去。

I have a monitoring app that displays a set of four parameters as animations (for example, it displays the temperature using a thermometer graphic). I also have one screen which plots all the four parameter values on a chart.

My requirement is this:

  1. Whenever the device is in Landscape mode, the chart should be displayed.
  2. Whenever the device is back in portrait mode, the earlier animation screen should be displayed.

I'm wondering if it is possible to provide different functionality based on the orientation. I see 2 options

  1. Override Activity.onConfigurationChanged() - but then what? Can i do a setContentView() at this point? Or, can i launch a different Activity (one which displays the Chart in a separate, lanscape-mode-only Activity)?
  2. Override Application.onConfigurationChanged() method. But I frankly haven't a clue as to how to proceed with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌化 2024-12-12 03:45:49
  1. 是的,您可以在Activity.onConfigurationChanged()内调用setContentView()。您可以检查方向并相应地执行一些任务,即根据方向运行不同的代码。

  2. 正常行为是当方向改变时,系统会终止 Activity 并创建一个新的 Activity。您可以在活动清单中使用 android:configChanges="orientation" 来防止这种情况发生。在这种情况下,您需要重写 onConfigurationChanged(..) 方法,该方法将在发生更改时调用。请参阅处理运行时更改。

  1. Yes you can call setContentView() inside Activity.onConfigurationChanged(). You can check orientation and accordingly perform some tasks, i.e. run different code based on orientation.

  2. Normal behaviour is that when orientation changes, system kills Activity and creates a new one. You can prevent this with android:configChanges="orientation" in you activity manifest. In this case you need to override the onConfigurationChanged(..) method, which will be called when change happens. See handling runtime changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文