那么你想制作与矩形一样多的视图并改变它们的可见性?
不要那样做。你的布局里面会很乱。而是创建自定义视图并覆盖onDraw()。在onDraw中,您使用canvas.drawRect()来绘制矩形。这样你就可以轻松获得每秒30-60帧的速度。
这是一个简单而不完整的示例,但应该让您走上正确的轨道。
private class AmplitudeView extends View {
private int mWidth;
private int mHeight;
private Paint mRectPaint;
public AmplitudeView(Context context, AttributeSet attrs) {
super(context, attrs);
mRectPaint = new Paint() {
{
setStyle(Style.FILL);
}
};
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = w;
mHeight = h;
}
@Override
protected void onDraw(Canvas canvas) {
int numRects = 10;
int red = 255;
int green = 0;
int incr = 255/numRects;
for (int i = 0; i< numRects;i++){
//TODO calculate color based on amplitude
mRectPaint.setColor(Color.argb(0xff, red, green, 0));
//TODO calculate rectangle
canvas.drawRect(r, mRectPaint);
red-=incr;
green+=incr;
}
}
}