具有多个片段的单个 Activity
我是 Android 开发新手,一直专注于设计。我想设计一个具有多个片段的单个活动应用程序。但无论我怎么考虑,我都坚持设计。 我首先将片段视为组件或小部件,我可以将它们组织在屏幕上我想要的位置。但是单个activity只有一个xml视图布局,找不到解决办法。
这就是我想要的。
问题如下。
布局选择:我需要一个用于全屏片段屏幕 1 的布局,但需要另一个用于其他屏幕的分割布局。
键盘:如果我使用(游戏键盘)片段和(dico-键盘)片段为所有屏幕进行全屏片段布局,如何删除平板电脑上 dico 片段中的键盘?我可以在两个片段之间共享键盘代码吗?
我发现在运行时调用 setContentView 有点烦人,因为您必须重新分配变量并且不合适。 我发现的所有应用程序在布局上都是全屏单个片段,允许像 ViewPager 这样的库。我找不到带有片段组件的组合屏幕的示例。
您会选择什么布局,使用什么样的片段? 或者您知道一个允许将片段组合为屏幕上的小部件的库吗? 感谢您的帮助。
I m new to Android development and stuck with design. I d like to design a single activity application with multiple fragments. But whatever I consider, I m stuck with design.
I first considered fragments as components or widgets that I could organize where I wanted on my screen. But a single activity has only one xml view layout and can not find a solution.
Here is what I want.
The problems are the following.
The layout choice: I need a layout for full screen fragment screen 1 but another splitted one for other screens.
The keyboard: if I do a fullscreen fragment layout for all my screens with a (game-keyboard) fragment and (dico-keyboard) fragment, how do I remove the keyboard in dico fragment on tablets ? And can I share keyboard code between both fragments ?
I saw that calling setContentView during runtime is kinda annoying as you have to reassign your variables and is not suitable.
All the applications I find are fullscreen single fragment on layout allowing libs like ViewPager. I can not find an example of composed screen with fragment components.
What layout would you chose, with what kind of fragments ?
Or do you know a library that allow composing fragments as widgets on screen ?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
欢迎使用安卓。系好安全带,这将是一段颠簸的旅程。
首先,您应该花一些时间阅读 Android 开发人员指南。
开发人员指南 | Android 开发人员
针对您的特定挑战的见解是,布局是资源,并且您可以拥有根据配置而变化的布局资源。
例如,您可以拥有像
layout_main
这样的资源,其中一个 XML 文件适用于小型设备,另一个 XML 文件适用于大型设备。应用资源概述 | Android 开发者
创建备用布局|支持不同屏幕尺寸 | Android 开发人员
您可以使用 Android Studio 布局设计器在布局上排列片段。
Welcome to Android. Buckle up, it's going to be a bumpy ride.
First, you should spend some quality time with the Android Developer Guides.
Developer Guides | Android Developers
The insight for your particular challenge is that layouts are resources, and and you can have a layout resource that changes based on the configuration.
So for example, you could have a resource like
layout_main
with one XML file for small devices and a different XML file for large devices.App resources overview | Android Developers
Create alternate layouts | Support different screen sizes | Android Developers
You can arrange fragments on a layout using the Android Studio layout designer.
您可以添加片段并导航。
首先,您需要一个导航:在 Android Studio 的左侧,您可以找到资源管理器,然后单击导航,然后单击+ > 并选择导航资源文件
之后,您可以将片段添加到导航中:
新目的地(绿色+)(不要忘记为您的片段命名)。
之后,您可以将导航添加到 Activity 的 xml 中。您应该在 xml 中使用
app:menu=”@menu/bottom_nav_menu”
代码以下是有关该过程的视频:
https://www.youtube.com/watch?v=Chso6xrJ6aU
You can add Fragments and navigate.
First of all yu need a navigation: In the left hand side on Android Studio you can find the Resource Manager Then click to Navigation then click to + and choose the Navigation resource file
After this you can add fragment to the navigation:
New Destination (green +) (Don't forget to give name to your fragments).
After this you can add the navigation to your activity's xml. You should use the
app:menu=”@menu/bottom_nav_menu”
code in your xmlHere a video about the process:
https://www.youtube.com/watch?v=Chso6xrJ6aU