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


Java Gravity類代碼示例

本文整理匯總了Java中android.view.Gravity的典型用法代碼示例。如果您正苦於以下問題:Java Gravity類的具體用法?Java Gravity怎麽用?Java Gravity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: SetNewContents

import android.view.Gravity; //導入依賴的package包/類
private void SetNewContents(int key) {
    if (!Changes(key).equals("null")) {
        CardView.LayoutParams param = new CardView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        CardView card = new CardView(this);
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("DARK_THEME_KEY", false))
            card.setCardBackgroundColor(ContextCompat.getColor(this, R.color.DarkcolorPrimary));
        card.setCardElevation(5);
        card.setLayoutParams(param);
        card.setPadding(ConvertTopx(15), ConvertTopx(15), ConvertTopx(15), ConvertTopx(15));
        card.setUseCompatPadding(true);
        TextView changes = new TextView(this);
        changes.setGravity(Gravity.CENTER);
        changes.setPadding(ConvertTopx(5), ConvertTopx(5), ConvertTopx(5), ConvertTopx(5));
        changes.setText(Changes(key));
        changes.setTypeface(Typeface.MONOSPACE);
        if (firebaseRemoteConfig.getBoolean("mark_red") && key == 0)
            changes.setTextColor(Color.RED);
        card.addView(changes);
        layout.addView(card);
    }
    bar.setVisibility(View.GONE);
}
 
開發者ID:coder3101,項目名稱:Matrix-Calculator-for-Android,代碼行數:24,代碼來源:ChangeLogActivity.java

示例2: show

import android.view.Gravity; //導入依賴的package包/類
public AlertDialog show(Context context) {
    dialog = new AlertDialog.Builder(context).create();
    dialog.show();
    Window window = dialog.getWindow();
    window.setContentView(R.layout.dialog_date_time);
    window.setGravity(Gravity.CENTER);// 此處可以設置dialog顯示的位置
    //window.setWindowAnimations(R.style.in_left_out_right_style);
    window.setBackgroundDrawableResource(R.color.transparent);

    datePicker = (DatePicker) window
            .findViewById(R.id.date_time_datePicker1);
    datePicker.setCalendarViewShown(false);
    timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
    but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
    but_ok.setOnClickListener(this);
    return dialog;
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:18,代碼來源:DialogDate.java

示例3: addNextFragment

import android.view.Gravity; //導入依賴的package包/類
private void addNextFragment(Sample sample, ImageView squareBlue, boolean overlap) {
    SharedElementFragment2 sharedElementFragment2 = SharedElementFragment2.newInstance(sample);

    Slide slideTransition = new Slide(Gravity.RIGHT);
    slideTransition.setDuration(getResources().getInteger(R.integer.anim_duration_medium));

    ChangeBounds changeBoundsTransition = new ChangeBounds();
    changeBoundsTransition.setDuration(getResources().getInteger(R.integer.anim_duration_medium));

    sharedElementFragment2.setEnterTransition(slideTransition);
    sharedElementFragment2.setAllowEnterTransitionOverlap(overlap);
    sharedElementFragment2.setAllowReturnTransitionOverlap(overlap);
    sharedElementFragment2.setSharedElementEnterTransition(changeBoundsTransition);

    getFragmentManager().beginTransaction()
            .replace(R.id.sample2_content, sharedElementFragment2)
            .addToBackStack(null)
            .addSharedElement(squareBlue, getString(R.string.square_blue_name))
            .commit();
}
 
開發者ID:shenhuanet,項目名稱:AndroidOpen,代碼行數:21,代碼來源:SharedElementFragment1.java

示例4: add

import android.view.Gravity; //導入依賴的package包/類
public static void add(Activity activity) {
    WindowManager manager = ((WindowManager) activity
            .getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE));

    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags =
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            // Enable the notification to receive touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            // Draw over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height = (int) (50 * activity.getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;

    StatusBarOverlay view = new StatusBarOverlay(activity);

    manager.addView(view, localLayoutParams);
}
 
開發者ID:ngocdaothanh,項目名稱:cordova-plugin-unswipable-android-status-bar,代碼行數:24,代碼來源:StatusBarOverlay.java

示例5: handleTypedArray

import android.view.Gravity; //導入依賴的package包/類
private void handleTypedArray(Context context, AttributeSet attrs) {
    if (attrs == null) {
        return;
    }
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BannerStyle);
    mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.BannerStyle_banner_indicatorMargin, 5);
    mIndicatorSelectedResId = typedArray.getResourceId(R.styleable.BannerStyle_banner_indicatorSelected, R.drawable.indicator_oval_selected);
    mIndicatorUnselectedResId = typedArray.getResourceId(R.styleable.BannerStyle_banner_indicatorUnselected, R.drawable.indicator_oval_unselected);
    mScaleType = typedArray.getInt(R.styleable.BannerStyle_banner_scaleType, mScaleType);
    mDelayTime = typedArray.getInt(R.styleable.BannerStyle_banner_delayTime, 3000);
    mScrollTime = typedArray.getInt(R.styleable.BannerStyle_banner_scrollTime, 800);
    isAutoPlay = typedArray.getBoolean(R.styleable.BannerStyle_banner_isAutoPlay, true);
    mTitleBackground = typedArray.getColor(R.styleable.BannerStyle_banner_titleBackground, -1);
    mTitleHeight = typedArray.getDimensionPixelSize(R.styleable.BannerStyle_banner_titleHeight, -1);
    mTitleTextColor = typedArray.getColor(R.styleable.BannerStyle_banner_titleTextColor, -1);
    mTitleTextSize = typedArray.getDimensionPixelSize(R.styleable.BannerStyle_banner_titleTextSize, -1);
    mLayoutResId = typedArray.getResourceId(R.styleable.BannerStyle_banner_layoutId, mLayoutResId);
    mGravity = typedArray.getInt(R.styleable.BannerStyle_banner_indicatorGravity, Gravity.CENTER);

    mBannerStyle = typedArray.getInt(R.styleable.BannerStyle_banner_indicatorType, BannerStyle.CIRCLE_INDICATOR);
    typedArray.recycle();
}
 
開發者ID:lany192,項目名稱:BannerView,代碼行數:23,代碼來源:BannerView.java

示例6: onDraw

import android.view.Gravity; //導入依賴的package包/類
@Override
@SuppressLint({"DrawAllocation", "SetTextI18n"})
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode()) {//這段代碼在運行時不會執行,隻會在Studio編輯預覽時運行,不用在意性能問題
        int d = DensityUtil.dp2px(5);

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(0x44ffffff);
        paint.setStrokeWidth(DensityUtil.dp2px(1));
        paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
        canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);

        TextView textView = new TextView(getContext());
        textView.setText(getClass().getSimpleName()+" 虛假區域\n運行時代表下拉Header的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不會顯示任何東西");
        textView.setTextColor(0x44ffffff);
        textView.setGravity(Gravity.CENTER);
        textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
        textView.layout(0, 0, getWidth(), getHeight());
        textView.draw(canvas);
    }
}
 
開發者ID:scwang90,項目名稱:SmartRefreshLayout,代碼行數:24,代碼來源:FalsifyHeader.java

示例7: calculateDistanceToFinalSnap

import android.view.Gravity; //導入依賴的package包/類
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager,
                                          @NonNull View targetView) {
    int[] out = new int[2];

    if (layoutManager.canScrollHorizontally()) {
        if (gravity == Gravity.START) {
            out[0] = distanceToStart(targetView, getHorizontalHelper(layoutManager), false);
        } else { // END
            out[0] = distanceToEnd(targetView, getHorizontalHelper(layoutManager), false);
        }
    } else {
        out[0] = 0;
    }

    if (layoutManager.canScrollVertically()) {
        if (gravity == Gravity.TOP) {
            out[1] = distanceToStart(targetView, getVerticalHelper(layoutManager), false);
        } else { // BOTTOM
            out[1] = distanceToEnd(targetView, getVerticalHelper(layoutManager), false);
        }
    } else {
        out[1] = 0;
    }

    return out;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:GravityDelegate.java

示例8: prepareLayout

import android.view.Gravity; //導入依賴的package包/類
void prepareLayout() {
    int layoutResource;

    layoutResource = getLayoutResource();

    inflate(getContext(), layoutResource, this);
    setOrientation(VERTICAL);
    setGravity(Gravity.CENTER_HORIZONTAL);
    setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon);
    iconView.setImageResource(iconResId);

    if (type != Type.TABLET) {
        titleView = (TextView) findViewById(R.id.bb_bottom_bar_title);
        titleView.setText(title);
    }

    updateCustomTextAppearance();
    updateCustomTypeface();
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:22,代碼來源:BottomBarTab.java

示例9: setupStatusBarView

import android.view.Gravity; //導入依賴的package包/類
/**
 * 設置一個可以自定義顏色的狀態欄
 */
private void setupStatusBarView() {
    if (mBarParams.statusBarView == null) {
        mBarParams.statusBarView = new View(mActivity);
    }
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(mActivity));
    params.gravity = Gravity.TOP;
    if (!isNavigationAtBottom(mActivity)) {
        params.rightMargin = getNavigationBarWidth(mActivity);
    }
    mBarParams.statusBarView.setLayoutParams(params);
    mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
            mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
    mBarParams.statusBarView.setVisibility(View.VISIBLE);
    ViewGroup viewGroup = (ViewGroup) mBarParams.statusBarView.getParent();
    if (viewGroup != null)
        viewGroup.removeView(mBarParams.statusBarView);
    mViewGroup.addView(mBarParams.statusBarView);
}
 
開發者ID:penghongru,項目名稱:Coder,代碼行數:22,代碼來源:ImmersionBar.java

示例10: inflateTextView

import android.view.Gravity; //導入依賴的package包/類
private TextView inflateTextView() {
    GradientDrawable shape = new GradientDrawable();
    shape.setCornerRadius(8);
    shape.setColor(0xff000000 | mRandom.nextInt(0x00ffffff));
    TextView textView = new TextView(this);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.WHITE);
    textView.setWidth(150 + mRandom.nextInt(3) * 50);
    textView.setHeight(150 + mRandom.nextInt(3) * 50);
    textView.setTextSize(32);
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackgroundDrawable(shape);
    } else {
        textView.setBackground(shape);
    }
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            mList.removeViewWithAnimation(view);
        }
    });
    textView.setText(String.format(Locale.JAPAN, "%1$02d", mCounter++));
    return textView;
}
 
開發者ID:sjnyag,項目名稱:AnimationWrapLayout,代碼行數:25,代碼來源:MainActivity.java

示例11: addItem

import android.view.Gravity; //導入依賴的package包/類
private void addItem(SwipeMenuItem item, int id) {
	LayoutParams params = new LayoutParams(item.getWidth(),
			LayoutParams.MATCH_PARENT);
	LinearLayout parent = new LinearLayout(getContext());
	parent.setId(id);
	parent.setGravity(Gravity.CENTER);
	parent.setOrientation(LinearLayout.VERTICAL);
	parent.setLayoutParams(params);
	parent.setBackgroundDrawable(item.getBackground());
	parent.setOnClickListener(this);
	addView(parent);

	if (item.getIcon() != null) {
		parent.addView(createIcon(item));
	}
	if (!TextUtils.isEmpty(item.getTitle())) {
		parent.addView(createTitle(item));
	}

}
 
開發者ID:MedicationReminder,項目名稱:MedicationReminder,代碼行數:21,代碼來源:SwipeMenuView.java

示例12: onViewPositionChanged

import android.view.Gravity; //導入依賴的package包/類
@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
  float offset;
  final int childWidth = changedView.getWidth();

  // This reverses the positioning shown in onLayout.
  if (checkDrawerViewAbsoluteGravity(changedView, Gravity.LEFT)) {
    offset = (float) (childWidth + left) / childWidth;
  } else {
    final int width = getWidth();
    offset = (float) (width - left) / childWidth;
  }
  setDrawerViewOffset(changedView, offset);
  changedView.setVisibility(offset == 0 ? INVISIBLE : VISIBLE);
  invalidate();
}
 
開發者ID:rogues-dev,項目名稱:superglue,代碼行數:17,代碼來源:DebugDrawerLayout.java

示例13: ToastProgress

import android.view.Gravity; //導入依賴的package包/類
public ToastProgress(android.content.Context context) {
	super(context);
	this.ctx=context;
	this.h=new Handler();
	this.h2=new Handler();
	root = new LinearLayout(ctx);
	root.setPadding((int)dp2px(ctx, 20), (int)dp2px(ctx, 10), (int)dp2px(ctx, 20), (int)dp2px(ctx, 10));
	root.setOrientation(LinearLayout.HORIZONTAL);
	prog=new ProgressBar(ctx);
	prog.setLayoutParams(new LinearLayout.LayoutParams((int)dp2px(ctx, 20), (int)dp2px(ctx, 20)));
	root.addView(prog);
	clt=new TextView(ctx);
	clt.setTextSize(14);
	clt.setTextColor(Color.WHITE);
	LinearLayout.LayoutParams tlp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	tlp.gravity=Gravity.CENTER_VERTICAL;
	tlp.setMargins((int)dp2px(ctx,10),0,0,0);
	clt.setLayoutParams(tlp);
	root.addView(clt);
	shape = new GradientDrawable();
	shape.setShape(GradientDrawable.RECTANGLE);
}
 
開發者ID:agusibrahim,項目名稱:go-jay,代碼行數:23,代碼來源:ToastProgress.java

示例14: NotificationFooterLayout

import android.view.Gravity; //導入依賴的package包/類
public NotificationFooterLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    Resources res = getResources();
    mRtl = Utilities.isRtl(res);

    int iconSize = res.getDimensionPixelSize(R.dimen.notification_footer_icon_size);
    mIconLayoutParams = new LayoutParams(iconSize, iconSize);
    mIconLayoutParams.gravity = Gravity.CENTER_VERTICAL;
    // Compute margin start for each icon such that the icons between the first one
    // and the ellipsis are evenly spaced out.
    int paddingEnd = res.getDimensionPixelSize(R.dimen.notification_footer_icon_row_padding);
    int ellipsisSpace = res.getDimensionPixelSize(R.dimen.horizontal_ellipsis_offset)
            + res.getDimensionPixelSize(R.dimen.horizontal_ellipsis_size);
    int footerWidth = res.getDimensionPixelSize(R.dimen.bg_popup_item_width);
    int availableIconRowSpace = footerWidth - paddingEnd - ellipsisSpace
            - iconSize * MAX_FOOTER_NOTIFICATIONS;
    mIconLayoutParams.setMarginStart(availableIconRowSpace / MAX_FOOTER_NOTIFICATIONS);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:20,代碼來源:NotificationFooterLayout.java

示例15: layoutByDirection

import android.view.Gravity; //導入依賴的package包/類
private void layoutByDirection() {
    if (isReceivedMessage()) {
        setGravity(animationView, Gravity.LEFT | Gravity.CENTER_VERTICAL);
        setGravity(durationLabel, Gravity.RIGHT | Gravity.CENTER_VERTICAL);

        containerView.setBackgroundResource(R.drawable.nim_message_item_left_selector);
        containerView.setPadding(ScreenUtil.dip2px(15), ScreenUtil.dip2px(8), ScreenUtil.dip2px(10), ScreenUtil.dip2px(8));
        animationView.setBackgroundResource(R.drawable.nim_audio_animation_list_left);
        durationLabel.setTextColor(Color.BLACK);

    } else {
        setGravity(animationView, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        setGravity(durationLabel, Gravity.LEFT | Gravity.CENTER_VERTICAL);
        unreadIndicator.setVisibility(View.GONE);

        containerView.setBackgroundResource(R.drawable.nim_message_item_right_selector);
        containerView.setPadding(ScreenUtil.dip2px(10), ScreenUtil.dip2px(8), ScreenUtil.dip2px(15), ScreenUtil.dip2px(8));
        animationView.setBackgroundResource(R.drawable.nim_audio_animation_list_right);
        durationLabel.setTextColor(Color.WHITE);
    }
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:22,代碼來源:MsgViewHolderAudio.java


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