简体   繁体   English

如何在Android中实现片段中的3个选项卡和底部的4个选项卡

[英]How to implement 3 tabs in fragment and 4 tabs on the bottom in android

I have 4 activities in android. 我在android中有4个活动。 I want to implement 3 tabs in each activity and 4 tabs at bottom to control 4 activities. 我想在每个活动中实现3个标签,在底部实现4个标签,以控制4个活动。 For each activity, it has 3 fragments, and each tab control one fragment. 对于每个活动,它都有3个片段,每个选项卡控制一个片段。 For 4 Tabs at bottom, they just navigate to 4 activities and there are no relationship among the activities. 对于底部的4个选项卡,它们仅导航到4个活动,并且这些活动之间没有关系。 What's the practical way to implement 4 bottom tabs? 实施4个底部标签的实际方法是什么?

Thanks in advance! 提前致谢!

picture 1: first activity picture 2: second activity! 图1: 第一次活动图2: 第二次活动!

Create an XML file for the bottom tabs. 为底部选项卡创建XML文件。 It should be a horizontal LinearLayout (wrap_content height and match_parent width) with your four ImageView buttons that switch between activities. 它应该是水平的LinearLayout(wrap_content高度和match_parent宽度),带有四个在活动之间切换的ImageView按钮。 Each button's icon in the XML should have the unselected state. XML中每个按钮的图标应处于未选中状态。 Each button should be wrap_content and layout_weight="1". 每个按钮应为wrap_content和layout_weight =“ 1”。

In each of your activity's XML, make the root view a RelativeLayout, include the bottom-tab layout XML described above, make it alignParentBottom="true", and put the rest of your content above the tabs. 在每个活动的XML中,使根视图成为RelativeLayout,包括上述底部标签布局XML,使其成为alignParentBottom =“ true”,然后将其余内容放在标签上方。

In each activity's onCreate, find that Activity's ImageView button, and change the styling to the selected version. 在每个活动的onCreate中,找到该活动的ImageView按钮,然后将样式更改为所选版本。 Also set listeners on the other buttons to launch the corresponding activities (you could use a shared helper function for this to share the code). 还要在其他按钮上设置侦听器以启动相应的活动(您可以使用共享帮助器功能来共享代码)。

For the fragment tabs on each Activity, you can use the standard ViewPager and FragmentPagerAdapter that Google is encouraging. 对于每个活动上的片段选项卡,您可以使用Google鼓励的标准ViewPager和FragmentPagerAdapter。

Let me know if you need more details for any of this. 让我知道您是否需要更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM