安卓:是否有可能在屏幕上建立底部和顶部的标签? [英] Android: Is it possible to create both Bottom and Top tabs on the screen?

查看:152
本文介绍了安卓:是否有可能在屏幕上建立底部和顶部的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果它可能有在顶部和底部的不同选项卡,导致不同的活动,点击时。用Google搜索,但没有找到任何关于它。

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>

这是我已经改变了的ID的TabWidgets的通知。

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

这是只有一半的问题。另一半是怎样的来源$ C ​​$ C为核心的类 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 <一源href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.3_r1/android/widget/TabHost.java/"相对=nofollow>此处。查看源它pretty的明显code的一个mTabWidget,这是用非常具体的ID初始化= 标签 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里面是私人(他们为什么不保护?!?)。不管怎么说,既然你有源$ C ​​$ C,它是pretty的简单,这是可能做到这一点。

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,所以您可以访问那些没有<$ C变量/函数$ C>私人或公开),那么你就可以在XML替换单词 TabHost MyTabHost com.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.

从查看源$ C ​​$ C,很明显,这个功能默认不支持。但是 - 我认为,如果你真的想做到这一点,你可以看到一个办法

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.

这篇关于安卓:是否有可能在屏幕上建立底部和顶部的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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