gpt4 book ai didi

android - android中这个控件的名称是什么以及如何实现它?

转载 作者:行者123 更新时间:2023-12-04 17:07:06 27 4
gpt4 key购买 nike

Android Controls

最佳答案

是非标准控制。

我已经实现了。我以简单的方式完成了它,只需在 ImageView 上绘制我需要的所有内容即可。

我的代码如下所示。它可以进一步改进(例如移动大小或 xml 布局中的颜色定义),但您可以从中得到灵感。而且它没有考虑设备屏幕的不同尺寸和密度。

/**
* Padding between circles displaying position
*/
private static final int PADDING = 20;
/**
* Radius of circles displaying position
*/
private static final int RADIUS = 4;
// Color of the selected element's indicator
private int activeColor;
// Color of the not selected element's indicator
private int inactiveColor;

// Call this in View constructor or in activity onCreate()
Resources res = getResources();
activeColor = res.getColor(R.color.sliderActiveColor);
inactiveColor = res.getColor(R.color.sliderInactiveColor);

/**
* Draws position of current element.
* Call it on fling events.
* @param currentPosition Current element position
*/
protected void drawPosition(int currentPosition) {
// Control height
final int height = 20;
// Control width
final int bmpWidth = 200;

// Count of all elements
int count = viewFlipper.getChildCount();

// Calculate first element position on canvas
float initialPosition = bmpWidth / 2 - (count - 1) * (PADDING / 2 + RADIUS);
final int shift = PADDING + 2 * RADIUS;

Bitmap bitmap = Bitmap.createBitmap(bmpWidth, height, Config.ARGB_8888);

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Style.FILL);
Canvas c = new Canvas(bitmap);

for (int i = 0; i < count; i++) {
// Draw circle for each element, current element with different color
if (i == currentPosition) {
paint.setColor(activeColor);
} else {
paint.setColor(inactiveColor);
}
c.drawCircle(initialPosition + i * shift, PADDING / 2, RADIUS, paint);
}

// Draw on ImageView
sliderImage.setImageBitmap(bitmap);
}

结果:

Fling indicator

关于android - android中这个控件的名称是什么以及如何实现它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6043870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com