2

两者都有很多来源和样本。我需要一个以点为指示器的寻呼机,我正在使用 Android 5.0 上的新 Studio。

乍一看;

  • PagerSlidingTabStrip看起来更新,我设法将它作为一个 gradle 项目导入并进行测试。

  • ViewPagerIndicatorappstore 上的示例应用程序可能会被删除。帖子中的所有
    链接似乎都已损坏。而且我也无法作为
    Gradle 项目导入。

我倾向于使用,PagerSlidingTabStrip但我不确定是否可以使用“PagerSlidingTabStrip”轻松配置带有小点的分页,据我所知,它主要是为带有标题的标签设计的。

4

1 回答 1

5

这是您自己解决的超级简单的示例,这是一个示例。

在 ViewPager 下方添加一个 LinearLayout(@+id/indContainer) ,然后使用此代码设置点:

LinearLayout indContainer = (LinearLayout) findViewById(R.id.indicator_container);
    for(int x=0;x<yourData.size();x++){
        ImageView v = new ImageView(this);
        int px = (int)(4 * (getResources().getDisplayMetrics().densityDpi / 160));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayoutCompat.LayoutParams.WRAP_CONTENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT);
        params.setMargins(px,0,px,0);
        v.setLayoutParams(params);
        v.setImageResource(R.drawable.indicator_inactive);
        indContainer.addView(v);
    }

然后在您的 pageChangeListener 中:

LinearLayout indContainer = (LinearLayout) findViewById(R.id.indicator_container);
((ImageView) indContainer.getChildAt(position)).setImageResource(R.drawable.indicator_active);
((ImageView) indContainer.getChildAt(lastPage)).setImageResource(R.drawable.indicator_inactive);
lastPage = position;

根据需要调整指示器图标和大小

于 2015-01-16T15:16:31.067 回答