當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。