当前位置: 首页>>代码示例>>Java>>正文


Java Gravity.CENTER_HORIZONTAL属性代码示例

本文整理汇总了Java中android.view.Gravity.CENTER_HORIZONTAL属性的典型用法代码示例。如果您正苦于以下问题:Java Gravity.CENTER_HORIZONTAL属性的具体用法?Java Gravity.CENTER_HORIZONTAL怎么用?Java Gravity.CENTER_HORIZONTAL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.view.Gravity的用法示例。


在下文中一共展示了Gravity.CENTER_HORIZONTAL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getItemViewType

@Override public int getItemViewType(int position) {
  Snap snap = mSnaps.get(position);
  switch (snap.getGravity()) {
    case Gravity.CENTER_VERTICAL:
      return VERTICAL;
    case Gravity.CENTER_HORIZONTAL:
      return HORIZONTAL;
    case Gravity.START:
      return HORIZONTAL;
    case Gravity.TOP:
      return VERTICAL;
    case Gravity.END:
      return HORIZONTAL;
    case Gravity.BOTTOM:
      return VERTICAL;
  }
  return HORIZONTAL;
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:18,代码来源:SnapAdapter.java

示例2: getDx

private float getDx(final int width,
                    final int horizontalGravity,
                    final Paint paint,
                    final StaticLayout layout) {
    final boolean centered = paint.getTextAlign() == Paint.Align.CENTER;
    final float dx;
    switch (horizontalGravity) { // No support for GravityCompat.END
        case Gravity.CENTER_HORIZONTAL:
            dx = (width >> 1) - (centered ? 0 : (layout.getWidth() >> 1) - getPaddingLeft());
            break;
        default:
        case GravityCompat.START:
            dx = getPaddingLeft();
            break;
    }
    return dx;
}
 
开发者ID:tylersuehr7,项目名称:empty-state-recyclerview,代码行数:17,代码来源:TextStateDisplay.java

示例3: onLayout

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    if (mTitleContainerView != null) {
        int titleContainerViewWidth = mTitleContainerView.getMeasuredWidth();
        int titleContainerViewHeight = mTitleContainerView.getMeasuredHeight();
        int titleContainerViewTop = (b - t - mTitleContainerView.getMeasuredHeight()) / 2;
        int titleContainerViewLeft = getPaddingLeft();
        if ((mTitleGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.CENTER_HORIZONTAL) {
            // 标题水平居中
            titleContainerViewLeft = (r - l - mTitleContainerView.getMeasuredWidth()) / 2;
        } else {
            // 标题非水平居中
            // 计算左侧 View 的总宽度
            for (int leftViewIndex = 0; leftViewIndex < mLeftViewList.size(); leftViewIndex++) {
                View view = mLeftViewList.get(leftViewIndex);
                if (view.getVisibility() != GONE) {
                    titleContainerViewLeft += view.getMeasuredWidth();
                }
            }
        }
        mTitleContainerView.layout(titleContainerViewLeft, titleContainerViewTop, titleContainerViewLeft + titleContainerViewWidth, titleContainerViewTop + titleContainerViewHeight);
    }
}
 
开发者ID:coopese,项目名称:qmui,代码行数:24,代码来源:QMUITopBar.java

示例4: AllAppsBackgroundDrawable

public AllAppsBackgroundDrawable(Context context) {
    Resources res = context.getResources();
    mHand = new TransformedImageDrawable(res, R.drawable.ic_all_apps_bg_hand,
            0.575f, 0.f, Gravity.CENTER_HORIZONTAL);
    mIcons = new TransformedImageDrawable[4];
    mIcons[0] = new TransformedImageDrawable(res, R.drawable.ic_all_apps_bg_icon_1,
            0.375f, 0, Gravity.CENTER_HORIZONTAL);
    mIcons[1] = new TransformedImageDrawable(res, R.drawable.ic_all_apps_bg_icon_2,
            0.3125f, 0.2f, Gravity.CENTER_HORIZONTAL);
    mIcons[2] = new TransformedImageDrawable(res, R.drawable.ic_all_apps_bg_icon_3,
            0.475f, 0.26f, Gravity.CENTER_HORIZONTAL);
    mIcons[3] = new TransformedImageDrawable(res, R.drawable.ic_all_apps_bg_icon_4,
            0.7f, 0.125f, Gravity.CENTER_HORIZONTAL);
    mWidth = res.getDimensionPixelSize(R.dimen.all_apps_background_canvas_width);
    mHeight = res.getDimensionPixelSize(R.dimen.all_apps_background_canvas_height);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:16,代码来源:AllAppsBackgroundDrawable.java

示例5: handleStyledAttributes

@Override
protected void handleStyledAttributes(TypedArray a) {
	super.handleStyledAttributes(a);

	mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true);

	if (mListViewExtrasEnabled) {
		final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
				FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL);

		// Create Loading Views ready for use later
		FrameLayout frame = new FrameLayout(getContext());
		mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a);
		mHeaderLoadingView.setVisibility(View.GONE);
		frame.addView(mHeaderLoadingView, lp);
		mRefreshableView.addHeaderView(frame, null, false);

		mLvFooterLoadingFrame = new FrameLayout(getContext());
		mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a);
		mFooterLoadingView.setVisibility(View.GONE);
		mLvFooterLoadingFrame.addView(mFooterLoadingView, lp);

		/**
		 * If the value for Scrolling While Refreshing hasn't been
		 * explicitly set via XML, enable Scrolling While Refreshing.
		 */
		if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
			setScrollingWhileRefreshingEnabled(true);
		}
	}
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:31,代码来源:PullToRefreshListView.java

示例6: computeInsets

/**
 * Compute insets.
 *
 * <pre>
 *  ______________________
 * |_________dx/2_________|
 * |......| /'''''\|......|
 * |-dx/2-|| View ||-dx/2-|
 * |______| \_____/|______|
 * |________ dx/2_________|
 * </pre>
 *
 * @param dx the dx the horizontal unfilled space
 * @param dy the dy the horizontal unfilled space
 */
@SuppressLint("NewApi")
private void computeInsets(final int dx, final int dy) {
    int absoluteGravity = mGravity;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        absoluteGravity = Gravity.getAbsoluteGravity(mGravity, getLayoutDirection());
    }

    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            mHorizontalInset = 0;
            break;
        case Gravity.RIGHT:
            mHorizontalInset = dx;
            break;
        case Gravity.CENTER_HORIZONTAL:
        default:
            mHorizontalInset = dx / 2;
            break;
    }
    switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            mVerticalInset = 0;
            break;
        case Gravity.BOTTOM:
            mVerticalInset = dy;
            break;
        case Gravity.CENTER_VERTICAL:
        default:
            mVerticalInset = dy / 2;
            break;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:HoloCircularProgressBar.java

示例7: PRTHeader

public PRTHeader(Context context) {
	super(context);
	int[] size = R.getScreenSize(context);
	float screenWidth = size[0] < size[1] ? size[0] : size[1];
	float ratio = screenWidth / DESIGN_SCREEN_WIDTH;

	setOrientation(VERTICAL);

	LinearLayout llInner = new LinearLayout(context);
	LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_HORIZONTAL;
	addView(llInner, lp);

	ivArrow = new RotateImageView(context);
	int resId = R.getBitmapRes(context, "ssdk_oks_ptr_ptr");
	if (resId > 0) {
		ivArrow.setImageResource(resId);
	}
	int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
	lp = new LayoutParams(avatarWidth, avatarWidth);
	lp.gravity = Gravity.CENTER_VERTICAL;
	int avataPadding = (int) (ratio * DESIGN_AVATAR_PADDING);
	lp.topMargin = lp.bottomMargin = avataPadding;
	llInner.addView(ivArrow, lp);

	pbRefreshing = new ProgressBar(context);
	resId = R.getBitmapRes(context, "ssdk_oks_classic_progressbar");
	Drawable pbdrawable = context.getResources().getDrawable(resId);
	pbRefreshing.setIndeterminateDrawable(pbdrawable);
	llInner.addView(pbRefreshing, lp);
	pbRefreshing.setVisibility(View.GONE);

	tvHeader = new TextView(getContext());
	tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvHeader.setPadding(avataPadding, 0, avataPadding, 0);
	tvHeader.setTextColor(0xff09bb07);
	lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(tvHeader, lp);
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:40,代码来源:PRTHeader.java

示例8: updateLeftPositionByGravity

private void updateLeftPositionByGravity(ViewPosition pos, int size, int gravity) {
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case GravityCompat.END:
            pos.left += (size > 0) ? size : 0;
            break;

        case Gravity.CENTER_HORIZONTAL:
            pos.left += ((size > 0) ? size : 0) / 2;
            break;
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:11,代码来源:AutoLinearLayout.java

示例9: setTitleGravity

/**
 * 设置 TopBar 的 gravity,用于控制 title 和 subtitle 的对齐方式
 *
 * @param gravity 参考 {@link android.view.Gravity}
 */
public void setTitleGravity(int gravity) {
    mTitleGravity = gravity;
    if (mTitleView != null) {
        ((LinearLayout.LayoutParams) mTitleView.getLayoutParams()).gravity = gravity;
        if (gravity == Gravity.CENTER || gravity == Gravity.CENTER_HORIZONTAL) {
            mTitleView.setPadding(getPaddingLeft(), getPaddingTop(), getPaddingLeft(), getPaddingBottom());
        }
    }
    if (mSubTitleView != null) {
        ((LinearLayout.LayoutParams) mSubTitleView.getLayoutParams()).gravity = gravity;
    }
    requestLayout();
}
 
开发者ID:coopese,项目名称:qmui,代码行数:18,代码来源:QMUITopBar.java

示例10: PRTHeader

public PRTHeader(Context context) {
	super(context);
	int[] size = ResHelper.getScreenSize(context);
	float screenWidth = size[0] < size[1] ? size[0] : size[1];
	float ratio = screenWidth / DESIGN_SCREEN_WIDTH;

	setOrientation(VERTICAL);

	LinearLayout llInner = new LinearLayout(context);
	LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_HORIZONTAL;
	addView(llInner, lp);

	ivArrow = new RotateImageView(context);
	int resId = ResHelper.getBitmapRes(context, "ssdk_oks_ptr_ptr");
	if (resId > 0) {
		ivArrow.setImageResource(resId);
	}
	int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
	lp = new LayoutParams(avatarWidth, avatarWidth);
	lp.gravity = Gravity.CENTER_VERTICAL;
	int avataPadding = (int) (ratio * DESIGN_AVATAR_PADDING);
	lp.topMargin = lp.bottomMargin = avataPadding;
	llInner.addView(ivArrow, lp);

	pbRefreshing = new ProgressBar(context);
	resId = ResHelper.getBitmapRes(context, "ssdk_oks_classic_progressbar");
	Drawable pbdrawable = context.getResources().getDrawable(resId);
	pbRefreshing.setIndeterminateDrawable(pbdrawable);
	llInner.addView(pbRefreshing, lp);
	pbRefreshing.setVisibility(View.GONE);

	tvHeader = new TextView(getContext());
	tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvHeader.setPadding(avataPadding, 0, avataPadding, 0);
	tvHeader.setTextColor(0xff09bb07);
	lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(tvHeader, lp);
}
 
开发者ID:ittianyu,项目名称:POCenter,代码行数:40,代码来源:PRTHeader.java

示例11: onMeasure

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    LayoutParams titleLayoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    titleLayoutParams.gravity = Gravity.CENTER_HORIZONTAL;
    titleLayoutParams.topMargin = getMeasuredHeight() / 10;
    title.setLayoutParams(titleLayoutParams);

    int iconSize = getMeasuredHeight() / 2;
    LayoutParams iconLayoutParams = new LayoutParams(iconSize, iconSize);
    iconLayoutParams.topMargin = getMeasuredHeight() / 10;
    iconLayoutParams.gravity = Gravity.CENTER;
    icon.setLayoutParams(iconLayoutParams);
}
 
开发者ID:byvlstr,项目名称:blurdialog,代码行数:15,代码来源:BlurDialog.java

示例12: PRTHeader

public PRTHeader(Context context) {
	super(context);
	setOrientation(VERTICAL);

	LinearLayout llInner = new LinearLayout(context);
	LayoutParams lpInner = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpInner.gravity = Gravity.CENTER_HORIZONTAL;
	addView(llInner, lpInner);

	ivArrow = new RotateImageView(context);
	int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr");
	if (resId > 0) {
		ivArrow.setImageResource(resId);
	}
	int dp_32 = dipToPx(context, 32);
	LayoutParams lpIv = new LayoutParams(dp_32, dp_32);
	lpIv.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(ivArrow, lpIv);

	pbRefreshing = new ProgressBar(context);
	llInner.addView(pbRefreshing, lpIv);
	pbRefreshing.setVisibility(View.GONE);

	tvHeader = new TextView(getContext());
	tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
	tvHeader.setGravity(Gravity.CENTER);
	int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
	tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10);
	tvHeader.setTextColor(0xff000000);
	LayoutParams lpTv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpTv.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(tvHeader, lpTv);
}
 
开发者ID:liupengandroid,项目名称:ywApplication,代码行数:35,代码来源:FollowListPage.java

示例13: initView

private void initView() {
    mCameraView = (CameraView) findViewById(R.id.camera_view);
    viewMask = (MaskView) findViewById(R.id.view_mask);
    ibtCapture = (ImageButton) findViewById(R.id.ibt_capture);
    ivReturn = (ImageView) findViewById(R.id.iv_return);

    ibtCapture.setOnClickListener(this);
    ivReturn.setOnClickListener(this);

    AspectRatio currentRatio = mCameraView.getAspectRatio();
    cameraRatio = currentRatio.toFloat();
    mCameraWidth = (int) DisplayUtils.getScreenWidth(this);
    mCameraHeight = (int) (mCameraWidth * cameraRatio);

    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.width = mCameraWidth;
    layoutParams.height = mCameraHeight;
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
    viewMask.setLayoutParams(layoutParams);

    if (ratio > cameraRatio) {
        //如果传过来的ratio比屏幕的高宽比大,那么需要以屏幕高为标准
        RECT_HEIGHT = mCameraHeight - topBottom; //以宽为准,到CameraView上下保留一定的间距
        RECT_WIDTH = (int) (RECT_HEIGHT / ratio);
    } else {
        RECT_WIDTH = mCameraWidth - leftRight; //以宽为准,到CameraView两边保留一定的间距
        RECT_HEIGHT = (int) (RECT_WIDTH * ratio);
    }
    if (viewMask != null) {
        Rect screenCenterRect = DisplayUtils.createCenterScreenRect(mCameraWidth, mCameraHeight, RECT_WIDTH, RECT_HEIGHT);
        viewMask.setCenterRect(screenCenterRect);
    }

}
 
开发者ID:fengzhizi715,项目名称:Tess-TwoDemo,代码行数:34,代码来源:CameraActivity.java

示例14: onBindViewHolder

@Override public void onBindViewHolder(ViewHolder holder, int position) {
  Snap snap = mSnaps.get(position);
  holder.snapTextView.setText(snap.getText());

  if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
    holder.recyclerView.setLayoutManager(
        new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL,
            false));
    holder.recyclerView.setOnFlingListener(null);
    new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
  } else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL
      || snap.getGravity() == Gravity.CENTER_VERTICAL
      || snap.getGravity() == Gravity.CENTER) {
    holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(),
        snap.getGravity() == Gravity.CENTER_HORIZONTAL ? LinearLayoutManager.HORIZONTAL
            : LinearLayoutManager.VERTICAL, false));
    holder.recyclerView.setOnFlingListener(null);
    new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
  } else { // Top / Bottom
    holder.recyclerView.setLayoutManager(
        new LinearLayoutManager(holder.recyclerView.getContext()));
    holder.recyclerView.setOnFlingListener(null);
    new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
  }

  holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
      || snap.getGravity() == Gravity.END
      || snap.getGravity() == Gravity.CENTER_HORIZONTAL, snap.getApps()));
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:29,代码来源:SnapAdapter.java

示例15: getGravity

private int getGravity(int gravityEnum) {
    return (gravityEnum == 0 ? Gravity.START
            : gravityEnum == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.END) | Gravity.CENTER_VERTICAL;
}
 
开发者ID:PacktPublishing,项目名称:Expert-Android-Programming,代码行数:4,代码来源:FooterLayout.java


注:本文中的android.view.Gravity.CENTER_HORIZONTAL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。