0

我在 CustomDialog 中有一个简单的视图:

public class ColorPickerDialog extends Dialog 
{
    private static class ColorPickerView extends View
    {
        ColorPickerView(Context c, int color) 
        {
             super(c);
             //...
        }
        @Override 
        protected void onDraw(Canvas canvas) {
            //...
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            setMeasuredDimension(CENTER_X*2, CENTER_Y*2);
        }
    }

    public ColorPickerDialog(Context context,
                             int initialColor) {
        super(context);
        mInitialColor = initialColor;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(new ColorPickerView(getContext(), mInitialColor));
    }
}

如何添加到这个视图 SeekBar?

4

1 回答 1

1

您可以为颜色选择器和搜索栏创建一个容器类。

例如,如果您想垂直布局它们:

private static class ColorPickerContainer extends LinearLayout {

    private ColorPickerView colorPicker;
    private SeekBar seekBar;

    public ColorPickerContainer(Context context, int initialColor) {
        super(context);
        setOrientation(LinearLayout.VERTICAL);

        colorPicker = new ColorPickerView(context, initialColor);
        addView(colorPicker);

        seekBar = new SeekBar(context);
        addView(seekBar);
    }

    public ColorPickerView getColorPicker() {
        return colorPicker;
    }

    public SeekBar getSeekBar() {
        return seekBar;
    }
}
于 2012-11-22T10:13:51.530 回答