Android:在TabWidget中,有没有办法获取包含选项卡的视图?

发布于 2024-11-03 13:47:43 字数 791 浏览 1 评论 0原文

大家好 我正在尝试编写一个选项卡活动,其中每个选项卡都有一个自定义的指示器视图。 视图像这样膨胀:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

裂开嘴轻声笑有多痛 2024-11-10 13:47:43

你说你查看了选项卡的所有代码;只是调用 getTabWidget()< 出了什么问题/code>在您的活动中?

You said you looked through all the code for tabs; what was wrong with just calling getTabWidget() in your activity?

听不够的曲调 2024-11-10 13:47:43

您是否正在尝试从选项卡活动之一访问 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 the TabHost via getParent() from the child activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文