Android 保存方向上的视图位置已更改

发布于 2024-11-30 09:25:08 字数 753 浏览 0 评论 0原文

可能的重复:
Android - 禁用横向模式?

当方向更改时,我无法保存视图位置。 我认为这是因为随着方向的变化,它也会发生变化,我希望该视图保持在同一位置。例如,它位于屏幕的左上角,它会留在那里,并且无论设备的方向如何。 我正在使用某种绝对布局。因为我需要同时管理几个屏幕。 所以,我有 x/y 坐标系。我认为这是主要问题,但我无法解决它:(

我已附加图像,您可以看到我的问题。 正如您所看到的,第一个屏幕是纵向模式,视图位于左上角,但是当我更改为横向模式时,视图位置也更改为右上角。 我需要视图位置始终保持在左上角。

  1. http://imgur.com/qo19E&u2K0hl
  2. http://imgur.com/qo19El&u2K0h

抱歉屏幕不好。我仍在开发应用程序,无法提供更好的屏幕:)

Ps:如果您需要一些代码,只需说出您需要哪部分代码即可。

Possible Duplicate:
Android - disable landscape mode?

I can't save position of view when orientation changes.
I think it's because with orientation it also changes and I want that view stayed on the same position. For example of it was in the upper left corner of screen it stayed there and it doesn't matter what orientation of the device.
I'm using some kind of Absolute layout. Because I need to manage few screens at the same time.
So, i have x/y coordinate system. I think it's the main problem, but I can't solve it :(

I've attached images that you could see my problem.
As you can see first screen is portrait mode and View is located in upper-left corner, but when I changed to landscape mode position of view is also changed to upper-right corner.
And I need that position of view stayed always in left-upper corner.

  1. http://imgur.com/qo19E&u2K0hl
  2. http://imgur.com/qo19El&u2K0h

Sorry to bad screen. I'm still developing of an application and can't provide better screens :)

Ps: If you need some code, just say what part of code do you need.

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

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

发布评论

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

评论(2

萝莉病 2024-12-07 09:25:08

重复 Android - 禁用横向模式?

您可以强制 Activity 以特定方向运行。
在 AndroidManifest.xml 中使用属性“android:screenOrientation”

请参阅此处的示例:
http://developer.android.com/guide/topics/manifest/活动元素.html

Duplicate of Android - disable landscape mode?

You can force the activity to run in a particular orientation.
Inside the AndroidManifest.xml use the attribute "android:screenOrientation"

See here for an example:
http://developer.android.com/guide/topics/manifest/activity-element.html

酸甜透明夹心 2024-12-07 09:25:08

如果您能提供一些代码或屏幕截图,那就太好了。

无论如何,当方向改变时,您的活动将被破坏并重新创建。
如果您有一个设计良好的 xml 布局文件(使用 Linearlayout、relativelayout 和“wrap_content”、“fill_parent”等属性...),它将在 onCreate() 方法中重新加载它,因此所有调整大小都应该自动完成。

如果您的视图可以由用户移动或从运行时值加载,您可以保存它。例如,请看这篇文章: 覆盖方向改变但不重新启动 Activity 并传递状态数据

It would be nice if you could provide some code or screenshots.

Anyway, when the orientation changes, your activity is destroyed and recreated.
If you have a well designed xml layout file (using linearlayout, relativelayout and properties like "wrap_content", "fill_parent"...) it will reload it in the onCreate() method, so all the resizing should be done automatically.

If your views can be moved by the user or are loaded from runtime values, you can save it. Look at this post for exemple : Override Orientation Change But NOT Restart The Activity AND Pass State Data

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