自定义标签指示观点 [英] Custom tab indicator view

查看:654
本文介绍了自定义标签指示观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重现此选项卡指示器结构(屏幕是新星发射器):一个下拉菜单,在右下角的箭头

我有大约code没有问题,但我不能重现这个样子。
我想这样的:

<$p$p><$c$c>mBar.addTab(mBar.newTab().setText(ctx.getString(R.string.tab_actions)).setTabListener(this).setCustomView(R.layout.navigation_spinner));

其中毫巴是福尔摩斯的支持动作条。

这是我的布局:

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;的LinearLayout的android:layout_width =match_parent
    机器人:layout_height =match_parent机器人:layout_margin = - 10dp
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直&GT;
    &LT;按钮机器人:ID =@ + ID / button1的机器人:layout_width =match_parent
        机器人:layout_height =match_parent机器人:文本=按钮/&GT;&LT; / LinearLayout中&GT;

这是我的结果是:

的问题是,在中央标签按钮没有填满标签指示器。如何设置自定义视图完美地填补了指标无保证金或填充?或者我有一个不同的方式有像杉杉屏幕的结果接近呢?谢谢咨询


解决方案

你所试图做的是非常复杂,而且将很难实现。

如果你想下拉菜单,你可以尝试这些:

菜单/ options.xml:

 &LT;项目
    机器人:图标=@绘制/ ic_menu_sort
    机器人:showAsAction =ifRoom&GT;
    &LT;菜单&gt;
        &LT;项目
            机器人:ID =@ + ID / menuSortNewest
            机器人:标题=排序方式最新/&GT;
        &LT;项目
            机器人:ID =@ + ID / menuSortRating
            机器人:标题=按评价/&GT;
    &所述; /菜单&gt;
&LT; /项目&GT;

第二个选项:

菜单/ options.xml:

 &LT;菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
    &LT;项目
        机器人:ID =@ + ID / menuSort
        机器人:showAsAction =ifRoom
        机器人:actionLayout =@布局/ action_sort/&GT;
&所述; /菜单&gt;

布局/ action_sort.xml:

 &LT;微调的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@绘制/ ic_menu_refresh
    机器人:项=@阵列/命令/&GT;

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

I want to reproduce this tab indicator structure (screen is from nova launcher): a dropdown menu and an arrow in the right bottom corner.

I have no problem about code but i can't reproduce this appearance. I tried this:

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

where mBar is sherlock support actionBar.

This is my layout:

<?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>

and this is my result:

The problem is that the button in the central tab doesn't fill the tab indicator. How can i set a custom view that perfectly fill the indicator without margin or padding? Or i have to approach this in a different way to have the a result like the firs screen? Thanks in advice

解决方案

What you are trying to do is really complicated, and will be hard to achieve.

If you want drop down menus you can try those :

menu/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>

Second option:

menu/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>

layout/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" />

Docs for menu resources - http://developer.android.com/guide/topics/resources/menu-resource.html

这篇关于自定义标签指示观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆