Android - 仅刷新主要内容
还在搞乱我的第一个 Android 应用程序。基本上,我有一个带有菜单图标的固定页眉和固定页脚。它工作得很好,但我不想开始一个全新的活动,我只想更新我的应用程序的主要内容(我认为这会让它快 10 倍)。这是可行的吗?
Still messing with my first android application. Basically, I have a fixed header and a fixed footer with menu icons. It's working kind of well but instead of starting a whole new activity, I only want to update the main content of my application (which I assume would make it 10 times faster). Is that something do-able?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您没有使用该布局(动画等)做一些非常繁重的事情,那么实际上在切换活动时绘制新布局并不会对设备资源造成太大影响。您可能想了解如何设置视图的可见性:
http://developer.android.com/reference/android/view/View.html#setVisibility%28int%29
因此,如果您的主要内容位于容器内,则只需在 fx 时隐藏该容器即可。您的用户单击一个按钮,并显示其他内容(之前隐藏)。
Actually drawing a new layout when switching activities isn't that hefty on the device resources, assuming you're not doing some really heavy things with that layout(animation etc.). You probably want to check out how to set the visibility of views:
http://developer.android.com/reference/android/view/View.html#setVisibility%28int%29
So if your main content is inside a container, you simple hide that container when fx. your user clicks a button, and show the other content(which was hidden before) instead.
我会坚持对所有页面使用活动,因为这使用户能够使用本机后退按钮返回堆栈。如果您选择在活动中的视图之间切换,您还必须手动管理后退按钮硬键。
I would stick to using activities for all pages as this enables the user to go back in the stack using the native back button. If you instead chooses to switch between views in an activity you will also have to manually manage the back button hard key.