自定义标签指示器视图

时间:2012-10-01 20:31:00

标签: android android-layout android-widget actionbarsherlock

我想重现此标签指示器结构(屏幕来自nova启动器):下拉菜单和右下角的箭头。

enter image description here

我对代码没有问题,但我无法重现这种外观。 我试过这个:

mBar.addTab(mBar.newTab().setText(ctx.getString(R.string.tab_actions)).setTabListener(this).setCustomView(R.layout.navigation_spinner));

其中mBar是sherlock支持actionBar。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent" android:layout_margin="-10dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">
    <Button android:id="@+id/button1" android:layout_width="match_parent"
        android:layout_height="match_parent" android:text="Button" />

</LinearLayout>

这是我的结果:

enter image description here

问题是中央选项卡中的按钮未填充选项卡指示符。如何设置完全填充指标的自定义视图,无需边距或填充?或者我必须以不同的方式接近这个以获得像第一个屏幕的结果?谢谢你的建议

1 个答案:

答案 0 :(得分:0)

你要做的事情真的很复杂,很难实现。

如果您想要下拉菜单,可以试试:

菜单/ options.xml:

<item
    android:icon="@drawable/ic_menu_sort"
    android:showAsAction="ifRoom">
    <menu>
        <item
            android:id="@+id/menuSortNewest"
            android:title="Sort by newest" />
        <item
            android:id="@+id/menuSortRating"
            android:title="Sort by rating" />
    </menu>
</item>

第二个选项:

菜单/ options.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menuSort"
        android:showAsAction="ifRoom"
        android:actionLayout="@layout/action_sort"  />
</menu>

布局/ action_sort.xml:

<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_menu_refresh"
    android:entries="@array/order" />

菜单资源的文档 - http://developer.android.com/guide/topics/resources/menu-resource.html