Android:在TabWidget中,有没有办法获取包含选项卡的视图?
大家好 我正在尝试编写一个选项卡活动,其中每个选项卡都有一个自定义的指示器视图。 视图像这样膨胀:
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
specIndicatorView = inflater.inflate(R.layout.tab_indicator, null);
indicatorIv = (ImageView)specIndicatorView.findViewById(R.id.indicatorImage);
indicatorTv = (TextView)specIndicatorView.findViewById(R.id.indicatorText);
indicatorIv.setImageDrawable(context.getResources().getDrawable(indicatorImageRes));
indicatorTv.setText(indicatorTextRes);
问题是子视图中定义的布局参数不会影响它,这是因为我不知道如何将父视图传递给 inflate 方法。
我想做的就是拥有一个图像和一些文本,其中图像与指示器视图的顶部对齐,文本与指示器视图的底部对齐,但我还需要一些小调整,要求我使用此指示器策略。 我查看了整个选项卡机制的源代码,但无法弄清楚如何获取父视图,你知道该怎么做吗? 你有更好的方法来实现我的需要吗?
谢谢
Hi all
I'm trying to write a tab activity in which each of the tabs has a custom view for the indicator.
The view is inflated like so:
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
specIndicatorView = inflater.inflate(R.layout.tab_indicator, null);
indicatorIv = (ImageView)specIndicatorView.findViewById(R.id.indicatorImage);
indicatorTv = (TextView)specIndicatorView.findViewById(R.id.indicatorText);
indicatorIv.setImageDrawable(context.getResources().getDrawable(indicatorImageRes));
indicatorTv.setText(indicatorTextRes);
The problem is that the layout parameters that are defined in the child view do not affect it and that is because I don't know how to pass in the parent view to the inflate method.
All I'm trying to do is have an image and some text where the image is aligned to the top and the text is aligned to the bottom of the indicator view but I also need some little tweaks that require me to use this indicator strategy.
I've looked at the source of the entire tab mechanism and could not figure out how to get the parent view, do you know how to do it?
do you have a better way to achieve what I need?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你说你查看了选项卡的所有代码;只是调用
getTabWidget()< 出了什么问题/code>
在您的活动中?
You said you looked through all the code for tabs; what was wrong with just calling
getTabWidget()
in your activity?您是否正在尝试从选项卡活动之一访问
TabHost
?如果是这样,您应该能够通过getParent()
来自子活动。Are you trying to access the
TabHost
from within one of the tab activities? If so, you should be able to get to theTabHost
viagetParent()
from the child activity.