当前位置: 首页>>代码示例>>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;未经允许,请勿转载。