TabPageIndicator setVisibility()什么都不做

时间:2016-06-13 11:37:07

标签: android android-studio viewpagerindicator

我正在尝试在我的应用中使用TabPageIndicator,但是当我想要运行它时它总会崩溃。之后,我在android:visibility="gone"中设置了com.viewpagerindicator.TabPageIndicator,它不再崩溃,但现在无法显示。我已经使用了调试器,它达到了调用setVisibility()的程度。有谁知道如何在程序执行期间看到TabPageIndicator?当没有指标时,viewpager工作正常。

主叫代码:

private void displayWords() {
    ArrayList<Fragment> fragments = new ArrayList<>();
    for (String word:words)
    {
        fragments.add(WordFragment.newInstance(word));
    }

    wordsAdaptor adapter = new wordsAdaptor(getSupportFragmentManager(), fragments);

    viewPager.setAdapter(adapter);

    TabPageIndicator tabIndicator = (TabPageIndicator)findViewById(R.id.titles);

    tabIndicator.setViewPager(viewPager);
    tabIndicator.setVisibility(TabPageIndicator.VISIBLE);


}

适配器:

public class wordsAdaptor extends FragmentStatePagerAdapter {

    private ArrayList<Fragment> fragments;

    public wordsAdaptor(FragmentManager fm, ArrayList<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }
}

的xml:

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"

    android:layout_width = "match_parent"
    android:layout_height="match_parent"

    />

<com.viewpagerindicator.TabPageIndicator
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/titles"

    custom:color="@android:color/darker_gray"

    android:visibility="gone"

    android:layout_height="wrap_content"
    android:layout_width="fill_parent" />

编译指令:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.mcxiaoke.viewpagerindicator:library:2.4.1'

Internet权限在清单中定义。

0 个答案:

没有答案