當前位置: 首頁>>代碼示例>>Java>>正文


Java LinearLayout.setBaselineAligned方法代碼示例

本文整理匯總了Java中android.widget.LinearLayout.setBaselineAligned方法的典型用法代碼示例。如果您正苦於以下問題:Java LinearLayout.setBaselineAligned方法的具體用法?Java LinearLayout.setBaselineAligned怎麽用?Java LinearLayout.setBaselineAligned使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.LinearLayout的用法示例。


在下文中一共展示了LinearLayout.setBaselineAligned方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ColorPickerDialog

import android.widget.LinearLayout; //導入方法依賴的package包/類
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);
}
 
開發者ID:dftec-es,項目名稱:planetcon,代碼行數:58,代碼來源:ColorPickerDialog.java


注:本文中的android.widget.LinearLayout.setBaselineAligned方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。