大家好,我正在尝试编写一个选项卡活动,其中每个选项卡都有一个针对指标的自定义视图。视图像这样膨胀:
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机制的源码,不知道怎么获取父视图,你知道怎么做吗?你有更好的方法来实现我的需要吗?
谢谢