原生的 FragmentTabHost 无法自定义,tabwidget 总是按比例等大出现。不适合开发的灵活应用。
要想自定义tabwidget ,可以修改源码如下。注释掉注释的部分,Demo 见附件
@Override
public void addView(View child) {
if (child.getLayoutParams() == null) {
final LinearLayout.LayoutParams lp =new LayoutParams(100, ViewGroup.LayoutParams.MATCH_PARENT);
// final LinearLayout.LayoutParams lp = new LayoutParams(
// 0,
// ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
lp.setMargins(0, 0, 0, 0);
child.setLayoutParams(lp);
}
// Ensure you can navigate to the tab with the keyboard, and you can touch it
child.setFocusable(true);
child.setClickable(true);
super.addView(child);
// TODO: detect this via geometry with a tabwidget listener rather
// than potentially interfere with the view's listener
child.setOnClickListener(new TabClickListener(getTabCount() - 1));
child.setOnFocusChangeListener(this);
}