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 方法。

我要做的只是有一个图像和一些文本,其中图像与顶部对齐,文本与指示器视图的底部对齐,但我还需要一些小调整,需要我使用此指示器策略。看了整个tab机制的源码,不知道怎么获取父视图,你知道怎么做吗?你有更好的方法来实现我的需要吗?

谢谢

4

2 回答 2

2

您说您查看了标签的所有代码;只是调用getTabWidget()你的活动有什么问题?

于 2011-04-26T16:15:56.620 回答
0

您是否尝试TabHost从其中一个选项卡活动中访问?如果是这样,您应该能够从子活动中到达TabHostvia 。getParent()

于 2011-04-26T15:40:39.367 回答