Java Code Examples for android.widget.LinearLayout.setBaselineAligned()

The following are Jave code examples for showing how to use setBaselineAligned() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: planetcon   File: ColorPickerDialog.java   View Source Code Vote up 4 votes
public ColorPickerDialog(Context context, int defaultColor, int initialColor, OnColorSelectedListener onColorSelectedListener) {
    super(context);
    final Resources res = context.getResources();
    final int boxMax = res.getDimensionPixelOffset(R.dimen.color_box);
    final int margin = res.getDimensionPixelOffset(R.dimen.view_margin_small);

    mOnColorSelectedListener = onColorSelectedListener;
    mInitialColor = initialColor;

    setTitle(context.getString(R.string.dialog_color));
    setIcon(0);
    setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), onDialogClickListener);
    setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel), onDialogClickListener);

    // Main layout with fixed size
    LinearLayout mainLayout = new LinearLayout(context) {

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            int w = View.MeasureSpec.getSize(widthMeasureSpec);
            int h = View.MeasureSpec.getSize(heightMeasureSpec);

            // Force squared remaining space for color picker
            int boxSize = (int)Math.ceil(Math.min((double) w / (I_MAX + J_MAX), (double) h / I_MAX));
            boxSize = Math.min(boxSize, boxMax);
            w = Math.min(w, boxSize * (I_MAX + J_MAX));
            h = Math.min(h, boxSize * I_MAX);
            setMeasuredDimension(w, h);
        }

    };
    LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    mainLayout.setLayoutParams(linearParams);
    mainLayout.setGravity(Gravity.CENTER);
    mainLayout.setBaselineAligned(false);

    // Preset colors
    addPresetColorViews(context, mainLayout);

    // Color picker
    // For some reason, MATCH_PARENT here does not work properly in some devices
    linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
    linearParams.setMargins(margin, margin, margin, margin);
    mColorPickerView = new ColorPicker(context);
    mColorPickerView.setInitialColor(mInitialColor);
    mColorPickerView.setColor(defaultColor);
    mainLayout.addView(mColorPickerView, linearParams);

    // Layout needed to center the main layout inside the dialog
    linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setLayoutParams(linearParams);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.addView(mainLayout);
    setView(linearLayout, margin, margin, margin, margin);
}