Android 自定义操作栏选项卡视图忽略布局\u重力

Android 自定义操作栏选项卡视图忽略布局\u重力,android,android-layout,actionbarsherlock,Android,Android Layout,Actionbarsherlock,我希望在逐个选项卡的基础上覆盖选项卡样式,以便可以对某些选项卡应用效果,同时使其他选项卡保持正常 这是我用于自定义选项卡的布局XML <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" style="@style/CustomActionBarTabTextStyle" android:ell

我希望在逐个选项卡的基础上覆盖选项卡样式,以便可以对某些选项卡应用效果,同时使其他选项卡保持正常

这是我用于自定义选项卡的布局XML

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/CustomActionBarTabTextStyle"
    android:ellipsize="end"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center_vertical"/>

按照com.actionbarsherlock.internal.widget.ScrollingTabContainerView.TabView中update()中的实现,我们相应地设置了布局参数和文本椭圆。我的CustomActionBarTabTextStyle当前唯一覆盖的是文本大小


选项卡的呈现方式与没有自定义视图时完全相同,只是文本在选项卡内顶部对齐。层次结构查看器中的快速运行显示布局重力显示为无,而非自定义选项卡的布局重力显示为中心垂直。这怎么可能?有人有办法解决这个问题吗?我已经尝试过将android:layout\u gravity=“center\u vertical”放在各处的样式和主题中,但没有结果。

我现在有了一个可行的解决方案,但它不是很漂亮。设置自定义视图时,我必须显式创建和设置LayoutParams

tab.setCustomView(customtabviewresourceid);
TextView tv = ((TextView)tab.getCustomView());
tv.setText(tab.getText().toString().toUpperCase());
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity=Gravity.CENTER_VERTICAL;
tv.setLayoutParams(lp);
我仍然在寻找答案,因为我认为这不是最好的方法。理想情况下,这不应该在Java代码中完成