2016-09-26 28 views
-3

要使用圆形页面指示符,我应该使用哪些依赖关系?如何在水平滚动视图中滚动图像时制作圆形页面指示符?

这是我的依赖文件:

compile 'com.android.support:appcompat-v7:24.1.0' 
compile 'com.android.support:design:24.1.0' 
compile 'com.android.support:cardview-v7:24.1.0' 
compile 'com.android.support:support-v4:24.1.0' 
compile 'com.android.support:palette-v7:24.1.0' 
compile 'me.relex:circleindicator:[email protected]' 
testCompile 'junit:junit:4.12' 

回答

0

相反,我建议你在相同的布局使用简单的水平的LinearLayout与ViewPager,在它下面。并使用ViewPager中的页面填充此LinearLayout的尽可能多的TextView。将每个TextView的圆圈html代码作为文本。只需简单地使用textView.setText(Html.fromHtml("&#9675")); 然后动态更改页面更改时所选圆圈的颜色,并在每个TextView上添加onClickListener以更改ViewPager上的页面。使用相同的想法here。注意方法addBottomDots

private void addBottomDots(int currentPage) { 
    dots = new TextView[layouts.length]; 

    int[] colorsActive = getResources().getIntArray(R.array.array_for_active_dot); 
    int[] colorsInactive = getResources().getIntArray(R.array.array_for_inactive_dot); 

    dotsLayout.removeAllViews(); 
    for (int i = 0; i < dots.length; i++) { 
     dots[i] = new TextView(this); 
     dots[i].setText(Html.fromHtml("&#8226;")); 
     dots[i].setTextSize(35); 
     dots[i].setTextColor(colorsInactive[currentPage]); 
     dotsLayout.addView(dots[i]); 
    } 

    if (dots.length > 0) 
     dots[currentPage].setTextColor(colorsActive[currentPage]); 
} 

,并调用它每次页面变化:

public void onPageSelected(int position) { 
     addBottomDots(position); 
     //... and so on, your code goes here 
} 

希望它能帮助。