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