基于对显示的标题长度动态定位动作条微调的右上角箭头箭头、长度、动作、标题

由网友(昨夜星辰恰似你)分享简介:在Google+应用,右上角箭头的位置动作条 微调适应的长度当前字符串展示。例如,Spinner的长度看起来短时的家庭的是挑对时候的熟人的是挑选出来的。In the Google+ App, the position of the right corner arrow of the ActionBar Spinner...

在Google+应用,右上角箭头的位置动作条 微调适应的长度当前字符串展示。例如,Spinner的长度看起来短时的家庭的是挑对时候的熟人的是挑选出来的。

In the Google+ App, the position of the right corner arrow of the ActionBar Spinner adapts to the length of the current string showing. For example, the Spinner's length seems shorter when Family is picked versus when Acquaintances is picked.

我有什么做的就是右下角箭头,根据标题的长度动态定位?我的猜测是,有一个属性我可以设置的 styles.xml 的,将做到这一点对我来说。

What do I have to do to get the right corner arrow to position dynamically based on the title's length? My guess is that there's an attribute I can set in styles.xml that will do that for me.

下面是我的styles.xml:

Here's my styles.xml:

<style name="MyStyle" parent="android:style/Theme.Holo">
    <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
</style>

<style name="MyDropDownNav" parent="android:style/Widget.Holo.Spinner">
    <item name="android:AttributeHere">AttributeValue</item>
</style>

这里的code我在MainActivity.java:

Here's the code I have in my MainActivity.java:

ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

// Specify a SpinnerAdapter to populate the dropdown list.
SpinnerAdapter dataAdapter = new ArrayAdapter<String>(
        actionBar.getThemedContext(),
        android.R.layout.simple_list_item_1, android.R.id.text1,
        new String[] { "AAAAAAAAAAAAAAA", "BB" });

// Set up the dropdown list navigation in the action bar.
actionBar.setListNavigationCallbacks(dataAdapter, this);

不像在Google+中,我向右的箭头的位置始终是固定的。所以,如果我从下拉AAAAAAAAAAAAAAA为BB选择,箭头不动。

Unlike in Google+, the position of my right corner arrow is always fixed. So if I choose from "AAAAAAAAAAAAAAA" to "BB" from the dropdown, the arrow doesn't move at all.

推荐答案

请参考Android的纯日历,在它的适配器, getView()总是返回日历,使微调的宽度等于当前的项目。实际上,微调宽度动作条总是被计算为最长项的长度。 日历做了一些特殊的工艺在这里。

Please refer the code of android pure Calendar, in its adapter, getView() always returns the current item in Calendar so that the width of the Spinner is equal to the current item. Actually, the Spinner width in ActionBar is always calculated as the length of its longest item. Calendar does some special process here.