Android 圆形页面指示器 - 如何更改填充颜色更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23238298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Circle page indicator - how to change fill color changing
提问by user3414081
I'm using ViewPageIndicator, specifically CirclePageIndictorin my Android application. The requirement is that the fillColorwill move straight to the next circle in the indicator, without the situation like this one in the picture (the circle moves slowly and stays in the middle while paging)
我在我的 Android 应用程序中使用ViewPageIndicator,特别是CirclePageIndictor。要求是fillColor会直接移动到指示器中的下一个圆圈,不会出现图片中的这种情况(圆圈移动缓慢并在分页时停留在中间)
How can I do this?
我怎样才能做到这一点?
回答by marvz
You can try this on your xml:
你可以在你的 xml 上试试这个:
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
app:radius="12dp"
app:fillColor="@color/header_bg_color"
app:pageColor="#ffffff"
app:strokeColor="@color/header_bg_color"/>
and don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto" on your layout. E.g
并且不要忘记在您的布局上添加 xmlns:app="http://schemas.android.com/apk/res-auto"。例如
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
app:radius="12dp"
app:fillColor="@color/header_bg_color"
app:pageColor="#ffffff"
app:strokeColor="@color/header_bg_color"/>
</LinearLayout>
回答by alex
Set the snap attribute to true.
将 snap 属性设置为 true。
vpi:snap="true"
or
或者
vpi.setSnap(true);
回答by Pankaj Arora
final CirclePageIndicator circleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
circleIndicator.setViewPager(_pager);
final float density = getResources().getDisplayMetrics().density;
circleIndicator.setFillColor(0xFFFFFFFF);
circleIndicator.setStrokeColor(0xFFFFFFFF);
circleIndicator.setStrokeWidth(1);
circleIndicator.setRadius(6 * density);
回答by HannahCarney
try app:snap="true"
尝试应用程序:快照=“真”
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:snap="true"/>