START源码实例Demo

android.view.Gravity#START源码实例Demo

下面列出了android.view.Gravity#START 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LiuAGeAndroid   文件: DragGridView.java
/**
 * 创建窗口对象、添加我们要移动的View
 *
 * @param dragBitmap
 * @param x
 * @param y
 */
public void startDrag(Bitmap dragBitmap, int x, int y) {
    stopDrag();
    // 获取window界面的Params
    windowParams = new WindowManager.LayoutParams();
    // Gravity.TOP|Gravity.START;这个必须加
    windowParams.gravity = Gravity.TOP | Gravity.START;
    // 得到要移动的View左上角相对于屏幕的坐标
    windowParams.x = x - win_view_x;
    windowParams.y = y - win_view_y;
    // 设置拖拽item的宽和高
    windowParams.width = (int) (dragScale * dragBitmap.getWidth());   // 放大dragScale倍,可以设置拖动后的倍数
    windowParams.height = (int) (dragScale * dragBitmap.getHeight()); // 放大dragScale倍,可以设置拖动后的倍数
    this.windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    this.windowParams.format = PixelFormat.TRANSLUCENT;
    this.windowParams.windowAnimations = 0;
    ImageView iv = new ImageView(getContext());
    iv.setImageBitmap(dragBitmap);
    windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    windowManager.addView(iv, windowParams);
    dragImageView = iv;
}
 
源代码2 项目: AnimatedEditText   文件: AnimatedEditText.java
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (!mAnimated) {
        return;
    }

    updateColorsForState();

    boolean rightAligned = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || (getGravity() & Gravity.END) == Gravity.END;
    boolean leftAligned = (getGravity() & Gravity.LEFT) == Gravity.LEFT || (getGravity() & Gravity.START) == Gravity.START;

    if (rightAligned) {
        drawGravityRight(canvas);
    } else if (leftAligned) {
        drawGravityLeft(canvas);
    } else {
        drawGravityCenterHorizontal(canvas);
    }

}
 
private static Animator createTranslationDisappearAnimator(
    View sceneRoot, View view, @GravityFlag int slideEdge, @Px int slideDistance) {
  switch (slideEdge) {
    case Gravity.LEFT:
      return createTranslationXAnimator(view, 0, -slideDistance);
    case Gravity.TOP:
      return createTranslationYAnimator(view, 0, slideDistance);
    case Gravity.RIGHT:
      return createTranslationXAnimator(view, 0, slideDistance);
    case Gravity.BOTTOM:
      return createTranslationYAnimator(view, 0, -slideDistance);
    case Gravity.START:
      return createTranslationXAnimator(
          view, 0, isRtl(sceneRoot) ? -slideDistance : slideDistance);
    case Gravity.END:
      return createTranslationXAnimator(
          view, 0, isRtl(sceneRoot) ? slideDistance : -slideDistance);
    default:
      throw new IllegalArgumentException("Invalid slide direction: " + slideEdge);
  }
}
 
private static Animator createTranslationAppearAnimator(
    View sceneRoot, View view, @GravityFlag int slideEdge, @Px int slideDistance) {
  switch (slideEdge) {
    case Gravity.LEFT:
      return createTranslationXAnimator(view, slideDistance, 0);
    case Gravity.TOP:
      return createTranslationYAnimator(view, -slideDistance, 0);
    case Gravity.RIGHT:
      return createTranslationXAnimator(view, -slideDistance, 0);
    case Gravity.BOTTOM:
      return createTranslationYAnimator(view, slideDistance, 0);
    case Gravity.START:
      return createTranslationXAnimator(
          view, isRtl(sceneRoot) ? slideDistance : -slideDistance, 0);
    case Gravity.END:
      return createTranslationXAnimator(
          view, isRtl(sceneRoot) ? -slideDistance : slideDistance, 0);
    default:
      throw new IllegalArgumentException("Invalid slide direction: " + slideEdge);
  }
}
 
源代码5 项目: YCProgress   文件: CarlProgressbar.java
private void initView(Context context) {
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mLayoutParams = new WindowManager.LayoutParams();
    mLayoutParams.gravity = Gravity.START | Gravity.TOP;
    mLayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLayoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLayoutParams.format = PixelFormat.TRANSLUCENT;
    mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;
    } else {
        mLayoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
    }
}
 
源代码6 项目: android_9.0.0_r45   文件: LinearLayout.java
/**
 * Describes how the child views are positioned. Defaults to GRAVITY_TOP. If
 * this layout has a VERTICAL orientation, this controls where all the child
 * views are placed if there is extra vertical space. If this layout has a
 * HORIZONTAL orientation, this controls the alignment of the children.
 *
 * @param gravity See {@link android.view.Gravity}
 *
 * @attr ref android.R.styleable#LinearLayout_gravity
 */
@android.view.RemotableViewMethod
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.START;
        }

        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.TOP;
        }

        mGravity = gravity;
        requestLayout();
    }
}
 
源代码7 项目: GravityBox   文件: TouchInterceptor.java
private void startDragging(Bitmap bm, int x, int y) {
      stopDragging();

      mWindowParams = new WindowManager.LayoutParams();
      mWindowParams.gravity = Gravity.TOP | Gravity.START;
      mWindowParams.x = x;
      mWindowParams.y = y - mDragPoint + mCoordOffset;

      mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
      mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
      mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
              | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
              | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
              | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
              | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
      mWindowParams.format = PixelFormat.TRANSLUCENT;
      mWindowParams.windowAnimations = 0;

      Context context = getContext();
      ImageView v = new ImageView(context);
      int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);
v.setAlpha((float) 0.7);
      v.setBackgroundColor(backGroundColor);
      v.setImageBitmap(bm);
      mDragBitmap = bm;

      mWindowManager = (WindowManager) context.getSystemService("window");
      mWindowManager.addView(v, mWindowParams);
      mDragView = v;
  }
 
源代码8 项目: GotoSleep   文件: AboutPage.java
/**
 * Add a new group that will display a header in this AboutPage
 * <p>
 * A header will be displayed in the order it was added. For e.g:
 * <p>
 * <code>
 * new AboutPage(this)
 * .addItem(firstItem)
 * .addGroup("Header")
 * .addItem(secondItem)
 * .create();
 * </code>
 * <p>
 * Will display the following
 * [First item]
 * [Header]
 * [Second item]
 *
 * @param name the title for this group
 * @return this AboutPage instance for builder pattern support
 */
public AboutPage addGroup(String name) {

    TextView textView = new TextView(mContext);
    textView.setText(name);
    TextViewCompat.setTextAppearance(textView, R.style.about_groupTextAppearance);
    LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    if (mCustomFont != null) {
        textView.setTypeface(mCustomFont);
    }

    int padding = mContext.getResources().getDimensionPixelSize(R.dimen.about_group_text_padding);
    textView.setPadding(padding, padding, padding, padding);


    if (mIsRTL) {
        textView.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        textParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
    } else {
        textView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
        textParams.gravity = Gravity.START | Gravity.CENTER_VERTICAL;
    }
    textView.setLayoutParams(textParams);

    ((LinearLayout) mView.findViewById(R.id.about_providers)).addView(textView);
    return this;
}
 
源代码9 项目: AndroidSweetBehavior   文件: PopupIndicator.java
private WindowManager.LayoutParams createPopupLayout(IBinder token) {
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.START | Gravity.TOP;
    p.width = ViewGroup.LayoutParams.MATCH_PARENT;
    p.height = ViewGroup.LayoutParams.MATCH_PARENT;
    p.format = PixelFormat.TRANSLUCENT;
    p.flags = computeFlags(p.flags);
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    p.token = token;
    p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
    return p;
}
 
源代码10 项目: material   文件: Spinner.java
/**
 * Describes how the selected item view is positioned.
 *
 * @param gravity See {@link Gravity}
 *
 * @attr ref android.R.styleable#Spinner_gravity
 */
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0)
            gravity |= Gravity.START;
        mGravity = gravity;
        requestLayout();
    }
}
 
源代码11 项目: Transitions-Everywhere   文件: SidePropagation.java
@SuppressLint("RtlHardcoded")
private int getMaxDistance(@NonNull ViewGroup sceneRoot) {
    switch (mSide) {
        case Gravity.LEFT:
        case Gravity.RIGHT:
        case Gravity.START:
        case Gravity.END:
            return sceneRoot.getWidth();
        default:
            return sceneRoot.getHeight();
    }
}
 
private void updateFloatingMenu() {
    if (mConfig.isLeftHandMode()) {
        CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) mFam.getLayoutParams();
        lp.gravity = Gravity.START | Gravity.BOTTOM;
        mFam.setExpandDirection(FloatingActionsMenu.EXPAND_UP, FloatingActionsMenu.LABELS_ON_RIGHT_SIDE);
        mFam.setLayoutParams(lp);
    }
}
 
源代码13 项目: SlickForm   文件: SimpleTooltip.java
private PointF calculePopupLocation() {
    PointF location = new PointF();

    final RectF anchorRect = SimpleTooltipUtils.calculeRectInWindow(mAnchorView);
    final PointF anchorCenter = new PointF(anchorRect.centerX(), anchorRect.centerY());

    switch (mGravity) {
        case Gravity.START:
            location.x = anchorRect.left - mPopupWindow.getContentView().getWidth() - mMargin;
            location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
            break;
        case Gravity.END:
            location.x = anchorRect.right + mMargin;
            location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
            break;
        case Gravity.TOP:
            location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
            location.y = anchorRect.top - mPopupWindow.getContentView().getHeight() - mMargin;
            break;
        case Gravity.BOTTOM:
            location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
            location.y = anchorRect.bottom + mMargin;
            break;
        default:
            throw new IllegalArgumentException("Gravity must have be START, END, TOP or BOTTOM.");
    }

    return location;
}
 
源代码14 项目: GravitySnapHelper   文件: GravitySnapHelper.java
@Nullable
public View findSnapView(@NonNull RecyclerView.LayoutManager lm, boolean checkEdgeOfList) {
    View snapView = null;

    switch (gravity) {
        case Gravity.START:
            snapView = findView(lm, getHorizontalHelper(lm), Gravity.START, checkEdgeOfList);
            break;
        case Gravity.END:
            snapView = findView(lm, getHorizontalHelper(lm), Gravity.END, checkEdgeOfList);
            break;
        case Gravity.TOP:
            snapView = findView(lm, getVerticalHelper(lm), Gravity.START, checkEdgeOfList);
            break;
        case Gravity.BOTTOM:
            snapView = findView(lm, getVerticalHelper(lm), Gravity.END, checkEdgeOfList);
            break;
        case Gravity.CENTER:
            if (lm.canScrollHorizontally()) {
                snapView = findView(lm, getHorizontalHelper(lm), Gravity.CENTER,
                        checkEdgeOfList);
            } else {
                snapView = findView(lm, getVerticalHelper(lm), Gravity.CENTER,
                        checkEdgeOfList);
            }
            break;
    }
    if (snapView != null) {
        nextSnapPosition = recyclerView.getChildAdapterPosition(snapView);
    } else {
        nextSnapPosition = RecyclerView.NO_POSITION;
    }
    return snapView;
}
 
源代码15 项目: ShowcaseView   文件: ShowcaseViewBuilder.java
private void addCustomView(Canvas canvas) {
    if (mCustomView.size() != 0) {
        for (int i = 0; i < mCustomView.size(); i++) {
            float cy = mCustomView.get(i).getMeasuredHeight() / 2, cx = mCustomView.get(i).getMeasuredWidth() / 2;
            float diffY, diffX;
            float marginTop = mCustomViewTopMargins.get(i);
            float marginLeft = mCustomViewLeftMargins.get(i);
            float marginRight = mCustomViewRightMargins.get(i);
            float marginBottom = mCustomViewBottomMargins.get(i);
            mTargetViewGlobalRect = new Rect();
            mTargetView.getGlobalVisibleRect(mTargetViewGlobalRect);
            View view = mCustomView.get(i);
            switch (mCustomViewGravity.get(i)) {
                case Gravity.START:
                case Gravity.LEFT:
                    diffY = mCenterY - cy;
                    diffX = mCenterX - cx;
                    if (diffX < 0) {
                        view.layout(0, 0, (int) (mCenterX - view.getMeasuredWidth() - 2 * marginRight),
                                (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    } else {
                        view.layout((int) diffX, 0, (int) (view.getMeasuredWidth() - diffX - 2 * marginRight),
                                (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    }
                    break;

                case Gravity.TOP:
                    diffY = mCenterY - cy - 2 * mTargetView.getMeasuredHeight();
                    view.layout((int) (-marginLeft), 0, (int) (view.getMeasuredWidth() + marginLeft),
                            (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    break;

                case Gravity.END:
                case Gravity.RIGHT:
                    diffY = mCenterY - cy;
                    view.layout(-2 * mTargetViewGlobalRect.right, 0,
                            (int) (view.getMeasuredWidth() + 4 * marginLeft), (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    break;

                case Gravity.BOTTOM:
                    diffY = mCenterY - cy + 2 * mTargetView.getMeasuredHeight();
                    view.layout((int) (-marginLeft), 0, (int) (view.getMeasuredWidth() + marginLeft),
                            (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    break;

                default:
                    mCustomView.get(i).layout(0, 0, mCustomView.get(i).getMeasuredWidth(), mCustomView.get(i).getMeasuredHeight());
            }
            mCustomView.get(i).draw(canvas);
        }
    } else {
        Log.d(TAG, "No Custom View defined");
    }
}
 
源代码16 项目: BottomNavigationBar   文件: QBadgeView.java
private void findBadgeCenter() {
    float rectWidth = mBadgeTextRect.height() > mBadgeTextRect.width() ?
            mBadgeTextRect.height() : mBadgeTextRect.width();
    switch (mBadgeGravity) {
        case Gravity.START | Gravity.TOP:
            mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f;
            mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f;
            break;
        case Gravity.START | Gravity.BOTTOM:
            mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f;
            mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f);
            break;
        case Gravity.END | Gravity.TOP:
            mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f);
            mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f;
            break;
        case Gravity.END | Gravity.BOTTOM:
            mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f);
            mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f);
            break;
        case Gravity.CENTER:
            mBadgeCenter.x = mWidth / 2f;
            mBadgeCenter.y = mHeight / 2f;
            break;
        case Gravity.CENTER | Gravity.TOP:
            mBadgeCenter.x = mWidth / 2f;
            mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f;
            break;
        case Gravity.CENTER | Gravity.BOTTOM:
            mBadgeCenter.x = mWidth / 2f;
            mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f);
            break;
        case Gravity.CENTER | Gravity.START:
            mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f;
            mBadgeCenter.y = mHeight / 2f;
            break;
        case Gravity.CENTER | Gravity.END:
            mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f);
            mBadgeCenter.y = mHeight / 2f;
            break;
    }
    initRowBadgeCenter();
}
 
源代码17 项目: kcanotify   文件: KcaFleetCheckPopupService.java
@Override
public void onCreate() {
    super.onCreate();
    active = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && !Settings.canDrawOverlays(getApplicationContext())) {
        // Can not draw overlays: pass
        stopSelf();
    } else {
        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        deckInfoCalc = new KcaDeckInfo(getApplicationContext(), getBaseContext());

        contextWithLocale = getContextWithLocale(getApplicationContext(), getBaseContext());

        mInflater = LayoutInflater.from(contextWithLocale);
        notificationManager = NotificationManagerCompat.from(getApplicationContext());
        mView = mInflater.inflate(R.layout.view_fleet_check, null);
        mView.setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.view_fchk_head).setOnTouchListener(mViewTouchListener);
        ((TextView) mView.findViewById(R.id.view_fchk_title)).setText(getStringWithLocale(R.string.fleetcheckview_title));

        for (int fchk_id: FCHK_BTN_LIST) {
            mView.findViewById(fchk_id).setOnTouchListener(mViewTouchListener);
        }
        for (int fleet_id: FCHK_FLEET_LIST) {
            mView.findViewById(fleet_id).setOnTouchListener(mViewTouchListener);
        }

        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWidth = mView.getMeasuredWidth();
        popupHeight = mView.getMeasuredHeight();

        fchk_info = mView.findViewById(R.id.fchk_value);

        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                getWindowLayoutType(),
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mParams.gravity = Gravity.TOP | Gravity.START;
        Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
        Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));

        mParams.x = (screenWidth - popupWidth) / 2;
        mParams.y = (screenHeight - popupHeight) / 2;
        mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mManager.addView(mView, mParams);
    }
}
 
源代码18 项目: fab-toolbar   文件: FabToolbar.java
private int getGravity(int gravityEnum) {
	return (gravityEnum == 0 ? Gravity.START : gravityEnum == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.END)
			| Gravity.CENTER_VERTICAL;
}
 
源代码19 项目: kcanotify_h5-master   文件: KcaMapHpPopupService.java
@Override
public void onCreate() {
    super.onCreate();
    active = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && !Settings.canDrawOverlays(getApplicationContext())) {
        // Can not draw overlays: pass
        stopSelf();
    } else {
        broadcaster = LocalBroadcastManager.getInstance(this);
        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        data_receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                //String s = intent.getStringExtra(KCA_MSG_DATA);
                String s = dbHelper.getValue(DB_KEY_BATTLEINFO);
                broadcaster.sendBroadcast(new Intent(KCA_MSG_BATTLE_VIEW_REFRESH));
                Log.e("KCA", "KCA_MSG_BATTLE_INFO Received: \n".concat(s));
            }
        };

        LocalBroadcastManager.getInstance(this).registerReceiver((data_receiver), new IntentFilter(KCA_MSG_BATTLE_INFO));

        LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        notificationManager = NotificationManagerCompat.from(getApplicationContext());
        mView = mInflater.inflate(R.layout.view_map_hp, null);
        mView.setOnTouchListener(mViewTouchListener);
        ((TextView) mView.findViewById(R.id.view_hp_title)).setText(getStringWithLocale(R.string.viewmenu_maphp_title));

        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWidth = mView.getMeasuredWidth();
        popupHeight = mView.getMeasuredHeight();

        hp_info = (TextView) mView.findViewById(R.id.hp_info);

        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                getWindowLayoutType(),
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mParams.gravity = Gravity.TOP | Gravity.START;
        Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
        Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));

        mParams.x = (screenWidth - popupWidth) / 2;
        mParams.y = (screenHeight - popupHeight) / 2;
        mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mManager.addView(mView, mParams);
    }
}
 
源代码20 项目: android_9.0.0_r45   文件: RelativeLayout.java
/**
 * Describes how the child views are positioned. Defaults to
 * <code>Gravity.START | Gravity.TOP</code>.
 *
 * <p>Note that since RelativeLayout considers the positioning of each child
 * relative to one another to be significant, setting gravity will affect
 * the positioning of all children as a single unit within the parent.
 * This happens after children have been relatively positioned.</p>
 *
 * @param gravity See {@link android.view.Gravity}
 *
 * @see #setHorizontalGravity(int)
 * @see #setVerticalGravity(int)
 *
 * @attr ref android.R.styleable#RelativeLayout_gravity
 */
@android.view.RemotableViewMethod
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.START;
        }

        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.TOP;
        }

        mGravity = gravity;
        requestLayout();
    }
}