0

如何在不隐藏第二个单词的情况下显示包含多个单词的页面标题?

这是解释:

在此处输入图像描述

蓝色标签标题是一个单词的普通标题。红色标题标签包含 2 个单词,但仅显示 1 个。

代码如下:

我如何在活动中声明寻呼机:

// Icons in pager tabs
int[] icons = new int[] { 
R.drawable.ic_tab_contestazione, 
R.drawable.ic_tab_note, 
R.drawable.ic_tab_camera };

// Prepares the adapter to attach to the pager
mAdapter = new NuovaViolazioneAdapter(getSupportFragmentManager(), icons);

// Inflates pager
mViewPager = (SwipeableViewPager) findViewById(R.id.viol_classica_pager);
mViewPager.setAdapter(mAdapter);
mViewPager.setSwipeable(false);

// Inflates tab indicator (the upper clickable/scrollable bar)
mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
mIndicator.setViewPager(mViewPager);

// Sets the current page (used when rotated)
int page = getIntent().getIntExtra(WHICH_PAGE, 0);
mIndicator.setCurrentItem(page);

寻呼机适配器:

     /**
     * Extends FragmentPagerAdapter and Implemenets IconPagerAdapter (so the method getIconResId is allowed).
     * <p>Sets which fragment has to be inflated for each position. Sets the tab title for each fragement.
     */
    class NuovaViolazioneAdapter extends FragmentStatePagerAdapter implements IconPagerAdapter {

        private int[] icons;

        public NuovaViolazioneAdapter(FragmentManager fm, int[] icons) {
            super(fm);
            this.icons = icons;
        }

        @Override
        public Fragment getItem(int position) {

            switch (position) {
            case POSITION_M_CONTESTAZIONE:
                return MContestazioneFragment_.getInstance();
            case POSITION_NOTE:
                return NoteFragment_.getInstance();
            case POSITION_FOTO:
                return FotoFragment_.getInstance();
            }
            return null;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return NuovaViolazioneActivity.CONTENT[position
                    % NuovaViolazioneActivity.CONTENT.length]
                    .toUpperCase(Locale.ITALIAN);
        }

        @Override
        public int getIconResId(int index) {
            return icons[index];
        }
    }
4

2 回答 2

0

从您的布局中,一个选项应该可用android:Layout_weightSum标志..请维护您要在屏幕上显示的选项卡数量。

于 2013-11-30T07:30:11.653 回答
0

我刚遇到同样的问题。

TabPageIndicator 的默认样式有 android:maxLines=1

如果将其更改为 2,则至少第二个单词将显示在第二行。我还在努力研究如何将它们全部显示在一条线上。

于 2013-11-30T07:03:46.053 回答