2012-11-22 92 views
0

我有內部CustomDialog一個簡單的觀點:任何Android視圖添加到自定義視圖

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)); 
    } 
} 

如何添加這種觀點搜索欄?

+0

你想添加一個'SeekBar'到'ColorPickerView'?或者你的對話? – fiddler

+0

給我的ColorPickerView – Leo

回答

1

你可以爲你的顏色選擇器和seekbar創建一個容器類。

舉例來說,如果你想垂直佈局他們:

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; 
    } 
} 
+0

好的解決方案!是工作 – Leo