Android:是否可以在屏幕上同时创建底部和顶部选项卡? [英] Android: Is it possible to create both Bottom and Top tabs on the screen?

查看:12
本文介绍了Android:是否可以在屏幕上同时创建底部和顶部选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在顶部和底部有不同的选项卡,从而在单击时导致不同的活动.谷歌了它,但没有找到任何关于它的信息.

I would like to know if its possible to have different tabs on the top and bottom that lead to different activities when clicked. Googled it but didnt find anything about it.

谢谢

推荐答案

Android 的好处是你想做的几乎所有事情都应该是可能的.如果我们要更改您的 XML,我们会将其更改为:

The good thing with Android is that almost everything you want to do should be possible. If we were to alter your XML we would change it to something like:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TabWidget
        android:id="@android:id/tabs_top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />

    <TabWidget
        android:id="@android:id/tabs_bottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0" />
</LinearLayout>

</TabHost>

请注意,我更改了 TabWidgets 的 ID.

Notice that I've changed the ID's of the TabWidgets.

这只是问题的一半.另一半是核心类 TabHost 的源代码应该如何改变以适应这种变化.

This is only half of the problem. The other half is how the source code for the core class TabHost should altered to accommodate this change.

您可以查看原始TabHost的来源这里.查看源代码很明显,代码有一个 mTab​​Widget,它是使用非常特定的 ID = tabs (com.android.internal.R.id.tabs).我们已经更改了 ID,所以我们应该注意这一点.

You can review the source of the original TabHost here. Looking at the source it's pretty obvious the code has a single mTabWidget and this is initialized using the very specific ID = tabs (com.android.internal.R.id.tabs). We've changed the ID's so we should be mindful of this.

那么,我们怎样才能改变原始来源呢?一种方法是创建我们自己的类并扩展核心 TabHost.这并不容易,因为原始 TabHost 中的一半函数和成员是 private (为什么它们不是 protected?!?).不管怎样,既然你有源代码,而且很简单,是可以做到的.

So, how can we alter the original source? One approach is to make our own class and extend the core TabHost. This will not be easy because half of the functions and members inside the original TabHost are private (why aren't they protected?!?). Anyways, since you have the source code and it's pretty simple, it's possible to do it.

假设您的新扩展类是 MyTabHost (可能将其放在与原始 TabHost 相同的包中,这样您就可以访问没有 private 的变量/函数或public),那么您可以在 XML 中将单词 TabHost 替换为 MyTabHostcom.yourpackage.MyTabHost 实际上) 然后您的类将在 XML 中使用,而不是原来的.

Let's say your new extended class is MyTabHost (potentially place it in the same package as the original TabHost just so you can access variables/functions which have no private or public), then you can replace in the XML the word TabHost with MyTabHost or com.yourpackage.MyTabHost actually) and then your class will be used in the XML instead of the original.

通过查看源代码,很明显默认情况下不支持此功能.但是 - 我认为如果你真的想实现它,你可以找到方法.

From looking at the source code, it's obvious that this feature isn't supported by default. But - I think that if you really want to make it happen, you can see a way.

这篇关于Android:是否可以在屏幕上同时创建底部和顶部选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆