Android的Tabhost问题 - .setIndicator [英] Android Tabhost Problem - .setIndicator

查看:148
本文介绍了Android的Tabhost问题 - .setIndicator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我要澄清,我已经提到相关的SO问题。机器人 - TAbhost

First let me clarify that i have already referred the SO question related to "Android - TAbhost".

我已经做了google搜索关于Android的Tabhost,但未能找到解决方案。

I have done googling about "Android Tabhost" but failed to find the solution.

我的问题是:

如果是具有3;选项卡,然后它是好的。 但 Supporse如果我们有4个标签带指示灯的标题为TabHost1,TabHost2,TabHost3,TabHost4)。但这个标题标签中没有获得装用标签。所以有没有什么办法,以适应标题文本(即指标)的标签里面??

If are having <3 tabs then it is fine. but Supporse if we are having 4 tabs with indicator title as TabHost1, TabHost2, TabHost3, TabHost4). But this title in Tab does not get fitted with tab. so is there any way to fit the Title Text (i.e. indicator) inside the tab ??

推荐答案

我以为我们的问题的根源是在框架中的code的地方。果然,我发现了一些线索:

I thought the source of our issue was somewhere in the framework's code. And sure enough, I found some clues :

首先,如果你看里面的<一个href="http://www.google.co.in/$c$csearch/p?hl=fr#uX1GffpyOZk/core/java/android/widget/TabWidget.java&q=class%3atranslateanimation&d=3&l=89"相对=nofollow> TabWidget code ,你会看到你的 setIndicator 传递给称为内部类 LabelIndicatorStrategy 这将采取相关膨胀到标签的顶部视图的照顾。使用XML文件<一个这样的通货膨胀做的是href="http://www.google.co.in/$c$csearch/p?hl=fr#uX1GffpyOZk/core/res/res/layout/tab_indicator.xml&q=tab_indicator&exact_package=git://android.git.kernel.org/platform/frameworks/base.git&sa=N&cd=1&ct=rc"相对=nofollow> tab_indicator.xml 。这种布局是基于 RelativeLayout的包含的ImageView 的TextView 。如果你看一下TextView中的属性,你会看到,它指的是在Android的风格<一个href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml#l517"相对=nofollow> styles.xml 。在这里,最后,你就会意识到,我们有:

First, if you look inside the TabWidget code, you will see that the label you set in setIndicator is passed to an inner class called LabelIndicatorStrategy which will take care of inflating the view associated to the top part of the tab. This inflation is done using an xml file tab_indicator.xml. This layout is based on a RelativeLayout containing an ImageView and a TextView. And if you look at the properties of the textview, you will see that it refers to a style in android styles.xml. And here finally, you realize that we have THAT :

<item name="ellipsize">marquee</item>
<item name="singleLine">true</item>

所以,现在,2个选择:
首先,通过创建您自己的风格,这在我看来是真的无痛的方式,然后更改这些属性,以适合你的好东西覆盖的风格。虽然结果可能不是很好看。这将需要一些测试。
或者,戴上手套,从TabWidget类复制code,因为这里的另一个问题是,我mentionned内部类是...私人所以,没有继承可能的,如果我没有记错...所以我想想,很多很多比styles.xml的方式更多的痛苦。 希望这会激励你,请给我你所得到的,请的。我仍然有兴趣。

So, now, 2 options :
First, override the style by creating your own style, which in my opinion would be the really painless way and then change these properties to something that suits you better. Though the result might not be very nice. this will require some testing.
Or, put on your gloves and copy the code from the TabWidget class, because another issue here is that the inner class I mentionned is... PRIVATE so, no inheritance possible if I'm not mistaken... SO I think, much much more pain than the styles.xml's way. Hope this will inspire you, keep me posted of what you get please. I'm still interested.

这篇关于Android的Tabhost问题 - .setIndicator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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