Java Code Examples for android.view.Gravity#BOTTOM

The following examples show how to use android.view.Gravity#BOTTOM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WXSwipeLayout.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Init refresh view or loading view
 */
private void setRefreshView() {
  // SetUp HeaderView
  FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 0);
  headerView = new WXRefreshView(getContext());
  headerView.setStartEndTrim(0, 0.75f);
  headerView.setBackgroundColor(mRefreshViewBgColor);
  headerView.setProgressBgColor(mProgressBgColor);
  headerView.setProgressColor(mProgressColor);
  headerView.setContentGravity(Gravity.BOTTOM);
  addView(headerView, lp);

  // SetUp FooterView
  lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 0);
  lp.gravity = Gravity.BOTTOM;
  footerView = new WXRefreshView(getContext());
  footerView.setStartEndTrim(0.5f, 1.25f);
  footerView.setBackgroundColor(mRefreshViewBgColor);
  footerView.setProgressBgColor(mProgressBgColor);
  footerView.setProgressColor(mProgressColor);
  footerView.setContentGravity(Gravity.TOP);
  addView(footerView, lp);
}
 
Example 2
Source File: CustomTabBottomBarDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
private void hideBottomBar() {
    if (mBottomBarView == null) return;
    ((ViewGroup) mBottomBarView.getParent()).removeView(mBottomBarView);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.BOTTOM;
    final ViewGroup compositorView = mActivity.getCompositorViewHolder();
    compositorView.addView(mBottomBarView, lp);
    compositorView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            compositorView.removeOnLayoutChangeListener(this);
            mBottomBarView.animate().alpha(0f).translationY(mBottomBarView.getHeight())
                    .setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE)
                    .setDuration(SLIDE_ANIMATION_DURATION_MS)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            ((ViewGroup) mBottomBarView.getParent()).removeView(mBottomBarView);
                            mBottomBarView = null;
                        }
                    }).start();
        }
    });
}
 
Example 3
Source File: SatelliteMenuView.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
public void setImgUrl(String url) {
    final Context context = getContext();
    ImageView imageView = new ImageView(context);
    ImageLoader.load(context, url, imageView);
    final int size = (int) (SIZE * BUTTON_RATIO);
    LayoutParams params = new LayoutParams(size, size);
    params.gravity = Gravity.END | Gravity.BOTTOM;
    addView(imageView, params);
    mButtonView = imageView;
    mButtonView.setOnClickListener(v -> {
        if (isOpen) {
            close();
        } else {
            show();
        }
    });
}
 
Example 4
Source File: FloatingLabelLayout.java    From FloatingLabelLayout with Apache License 2.0 6 votes vote down vote up
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof EditText) {
        // If we already have an EditText, throw an exception
        if (mEditText != null) {
            throw new IllegalArgumentException("We already have an EditText, can only have one");
        }

        // Update the layout params so that the EditText is at the bottom, with enough top
        // margin to show the label
        final LayoutParams lp = new LayoutParams(params);
        lp.gravity = Gravity.BOTTOM;
        lp.topMargin = (int) mLabel.getTextSize();
        params = lp;

        setEditText((EditText) child);
    }

    // Carry on adding the View...
    super.addView(child, index, params);
}
 
Example 5
Source File: GravityDelegate.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
int getSnappedPosition(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManager instanceof LinearLayoutManager) {
        if (gravity == Gravity.START || gravity == Gravity.TOP) {
            return ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
        } else if (gravity == Gravity.END || gravity == Gravity.BOTTOM) {
            return ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
        }
    }

    return RecyclerView.NO_POSITION;
}
 
Example 6
Source File: PopupDialog.java    From PopupLayout with Apache License 2.0 5 votes vote down vote up
private void configWindowLayoutParams(Window window,WindowManager.LayoutParams params){
    params.gravity= mGravity;
    if(mGravity==Gravity.LEFT||mGravity==Gravity.RIGHT){
        params.width= getWidthParams(WindowManager.LayoutParams.WRAP_CONTENT);
        params.height=getHeightParams(WindowManager.LayoutParams.MATCH_PARENT);
    }else if(mGravity==Gravity.TOP||mGravity==Gravity.BOTTOM){
        params.width= getWidthParams(WindowManager.LayoutParams.MATCH_PARENT);
        params.height=getHeightParams(WindowManager.LayoutParams.WRAP_CONTENT);
    }else{
        params.width= getWidthParams(WindowManager.LayoutParams.WRAP_CONTENT);
        params.height=getHeightParams(WindowManager.LayoutParams.WRAP_CONTENT);
    }
    window.setAttributes(params);
}
 
Example 7
Source File: AutoLinearLayout.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
private void updateTopPositionByGravity(ViewPosition pos, int size, int gravity) {
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.BOTTOM:
            pos.top += (size > 0) ? size : 0;
            break;

        case Gravity.CENTER_VERTICAL:
            pos.top += ((size > 0) ? size : 0) / 2;
            break;
    }
}
 
Example 8
Source File: GridLayoutManager.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void layoutChild(int rowIndex, View v, int start, int end, int startSecondary) {
    int sizeSecondary = mOrientation == HORIZONTAL ? v.getMeasuredHeight()
            : v.getMeasuredWidth();
    if (mFixedRowSizeSecondary > 0) {
        sizeSecondary = Math.min(sizeSecondary, mFixedRowSizeSecondary);
    }
    final int verticalGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int horizontalGravity = mGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    if (mOrientation == HORIZONTAL && verticalGravity == Gravity.TOP
            || mOrientation == VERTICAL && horizontalGravity == Gravity.LEFT) {
        // do nothing
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.BOTTOM
            || mOrientation == VERTICAL && horizontalGravity == Gravity.RIGHT) {
        startSecondary += getRowSizeSecondary(rowIndex) - sizeSecondary;
    } else if (mOrientation == HORIZONTAL && verticalGravity == Gravity.CENTER_VERTICAL
            || mOrientation == VERTICAL && horizontalGravity == Gravity.CENTER_HORIZONTAL) {
        startSecondary += (getRowSizeSecondary(rowIndex) - sizeSecondary) / 2;
    }
    int left, top, right, bottom;
    if (mOrientation == HORIZONTAL) {
        left = start;
        top = startSecondary;
        right = end;
        bottom = startSecondary + sizeSecondary;
    } else {
        top = start;
        left = startSecondary;
        bottom = end;
        right = startSecondary + sizeSecondary;
    }
    v.layout(left, top, right, bottom);
    updateChildOpticalInsets(v, left, top, right, bottom);
    updateChildAlignments(v);
}
 
Example 9
Source File: TextBannerView.java    From TextBannerView with Apache License 2.0 5 votes vote down vote up
/**
 * 设置数据集合伴随drawable-icon
 * @param datas 数据
 * @param drawable 图标
 * @param size 图标尺寸
 * @param direction 图标位于文字方位
 */
public void setDatasWithDrawableIcon(List<String> datas, Drawable drawable,int size, int direction){
    this.mDatas = datas;
    if (DisplayUtils.isEmpty(mDatas)){
        return;
    }
    mViewFlipper.removeAllViews();
    for (int i = 0; i < mDatas.size(); i++) {
        TextView textView = new TextView(getContext());
        setTextView(textView,i);

        textView.setCompoundDrawablePadding(8);
        float scale = getResources().getDisplayMetrics().density;// 屏幕密度 ;
        int muchDp = (int) (size * scale + 0.5f);
        drawable.setBounds(0, 0, muchDp, muchDp);
        if (direction==Gravity.LEFT){
            textView.setCompoundDrawables(drawable,null,null , null);//左边
        }else if (direction==Gravity.TOP){
            textView.setCompoundDrawables(null,drawable,null , null);//顶部
        }else if (direction==Gravity.RIGHT){
            textView.setCompoundDrawables(null,null, drawable, null);//右边
        }else if (direction==Gravity.BOTTOM){
            textView.setCompoundDrawables(null,null, null, drawable);//底部
        }


        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);//水平方向
        linearLayout.setGravity(mGravity);//子view显示位置跟随TextView
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.
                LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout.addView(textView,param);

        mViewFlipper.addView(linearLayout,i);//添加子view,并标识子view位置
    }
}
 
Example 10
Source File: PagerTitleStrip.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
void updateTextPositions(int position, float positionOffset, boolean force) {
    if (position != mLastKnownCurrentPage) {
        updateText(position, mPager.getAdapter());
    } else if (!force && positionOffset == mLastKnownPositionOffset) {
        return;
    }

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = currWidth / 2;

    final int stripWidth = getWidth();
    final int stripHeight = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    final int textPaddedLeft = paddingLeft + halfCurrWidth;
    final int textPaddedRight = paddingRight + halfCurrWidth;
    final int contentWidth = stripWidth - textPaddedLeft - textPaddedRight;

    float currOffset = positionOffset + 0.5f;
    if (currOffset > 1.f) {
        currOffset -= 1.f;
    }
    final int currCenter = stripWidth - textPaddedRight - (int) (contentWidth * currOffset);
    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    final int prevBaseline = mPrevText.getBaseline();
    final int currBaseline = mCurrText.getBaseline();
    final int nextBaseline = mNextText.getBaseline();
    final int maxBaseline = Math.max(Math.max(prevBaseline, currBaseline), nextBaseline);
    final int prevTopOffset = maxBaseline - prevBaseline;
    final int currTopOffset = maxBaseline - currBaseline;
    final int nextTopOffset = maxBaseline - nextBaseline;
    final int alignedPrevHeight = prevTopOffset + mPrevText.getMeasuredHeight();
    final int alignedCurrHeight = currTopOffset + mCurrText.getMeasuredHeight();
    final int alignedNextHeight = nextTopOffset + mNextText.getMeasuredHeight();
    final int maxTextHeight = Math.max(Math.max(alignedPrevHeight, alignedCurrHeight),
            alignedNextHeight);

    final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int prevTop;
    int currTop;
    int nextTop;
    switch (vgrav) {
        default:
        case Gravity.TOP:
            prevTop = paddingTop + prevTopOffset;
            currTop = paddingTop + currTopOffset;
            nextTop = paddingTop + nextTopOffset;
            break;
        case Gravity.CENTER_VERTICAL:
            final int paddedHeight = stripHeight - paddingTop - paddingBottom;
            final int centeredTop = (paddedHeight - maxTextHeight) / 2;
            prevTop = centeredTop + prevTopOffset;
            currTop = centeredTop + currTopOffset;
            nextTop = centeredTop + nextTopOffset;
            break;
        case Gravity.BOTTOM:
            final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
            prevTop = bottomGravTop + prevTopOffset;
            currTop = bottomGravTop + currTopOffset;
            nextTop = bottomGravTop + nextTopOffset;
            break;
    }

    mCurrText.layout(currLeft, currTop, currRight,
            currTop + mCurrText.getMeasuredHeight());

    final int prevLeft = Math.min(paddingLeft, currLeft - mScaledTextSpacing - prevWidth);
    mPrevText.layout(prevLeft, prevTop, prevLeft + prevWidth,
            prevTop + mPrevText.getMeasuredHeight());

    final int nextLeft = Math.max(stripWidth - paddingRight - nextWidth,
            currRight + mScaledTextSpacing);
    mNextText.layout(nextLeft, nextTop, nextLeft + nextWidth,
            nextTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
}
 
Example 11
Source File: CommonTabLayout.java    From FlycoTabLayout with MIT License 4 votes vote down vote up
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }

            ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
            if (mIconVisible) {
                iv_tab_icon.setVisibility(View.VISIBLE);
                CustomTabEntity tabEntity = mTabEntitys.get(i);
                iv_tab_icon.setImageResource(i == mCurrentTab ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon());
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        mIconWidth <= 0 ? LinearLayout.LayoutParams.WRAP_CONTENT : (int) mIconWidth,
                        mIconHeight <= 0 ? LinearLayout.LayoutParams.WRAP_CONTENT : (int) mIconHeight);
                if (mIconGravity == Gravity.LEFT) {
                    lp.rightMargin = (int) mIconMargin;
                } else if (mIconGravity == Gravity.RIGHT) {
                    lp.leftMargin = (int) mIconMargin;
                } else if (mIconGravity == Gravity.BOTTOM) {
                    lp.topMargin = (int) mIconMargin;
                } else {
                    lp.bottomMargin = (int) mIconMargin;
                }

                iv_tab_icon.setLayoutParams(lp);
            } else {
                iv_tab_icon.setVisibility(View.GONE);
            }
        }
    }
 
Example 12
Source File: TextStateDisplay.java    From empty-state-recyclerview with MIT License 4 votes vote down vote up
@Override
public void onDrawState(EmptyStateRecyclerView rv, Canvas canvas) {
    final int width = rv.getMeasuredWidth();
    final int height = rv.getMeasuredHeight();
    configureTextLayouts(width);

    // Account for vertical text gravity
    final int verticalGravity = textGravity&Gravity.VERTICAL_GRAVITY_MASK;
    float dy;
    switch (verticalGravity) {
        case Gravity.CENTER_VERTICAL:
            dy = (height >> 1) - ((int)getFullTextHeight() >> 1);
            break;
        case Gravity.BOTTOM:
            dy = height - getFullTextHeight();
            break;
        default:
        case Gravity.TOP:
            dy = 0;
            break;
    }
    dy += getPaddingTop();

    final int horizontalGravity = Gravity.getAbsoluteGravity(textGravity,
            ViewCompat.getLayoutDirection(rv))&Gravity.HORIZONTAL_GRAVITY_MASK;

    // Draw the title text
    canvas.save();
    canvas.translate(
            getDx(width, horizontalGravity, titlePaint, titleLayout),
            dy);
    this.titleLayout.draw(canvas);
    canvas.restore();

    // Add spacing for under the text with the title spacing
    dy += titleLayout.getHeight() + titleSpacing;

    // Draw the subtitle text under the title text
    canvas.save();
    canvas.translate(
            getDx(width, horizontalGravity, subtitlePaint, subtitleLayout),
            dy);
    this.subtitleLayout.draw(canvas);
    canvas.restore();
}
 
Example 13
Source File: DropDown.java    From Carbon with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    final Drawable buttonDrawable = drawable;
    if (buttonDrawable != null) {
        final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
        final int drawableHeight = buttonDrawable.getIntrinsicHeight();
        final int drawableWidth = buttonDrawable.getIntrinsicWidth();

        final int top;
        switch (verticalGravity) {
            case Gravity.BOTTOM:
                top = getHeight() - drawableHeight - getPaddingBottom();
                break;
            case Gravity.CENTER_VERTICAL:
                top = (getHeight() - drawableHeight - getPaddingTop() - getPaddingBottom()) / 2 + getPaddingTop();
                break;
            default:
                top = getPaddingTop();
        }
        final int bottom = top + drawableHeight;
        final int left = isButtonOnTheLeft() ? getPaddingLeft() : getWidth() - drawableWidth - getPaddingRight();
        final int right = isButtonOnTheLeft() ? drawableWidth + getPaddingLeft() : getWidth() - getPaddingRight();

        buttonDrawable.setBounds(left, top, right, bottom);

        final Drawable background = getBackground();
        if (background instanceof RippleDrawable) {
            //TODO: hotspotBounds
            // ((RippleDrawable)background).setHotspotBounds(left, top, right, bottom);
        }
    }

    super.onDraw(canvas);

    if (buttonDrawable != null) {
        // TODO: get rid of invalidate() loop
        if (animateColorChanges && tint != null && tintMode != null)
            buttonDrawable.setColorFilter(new PorterDuffColorFilter(tint.getColorForState(buttonDrawable.getState(), tint.getDefaultColor()), tintMode));

        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        if (scrollX == 0 && scrollY == 0) {
            buttonDrawable.draw(canvas);
        } else {
            canvas.translate(scrollX, scrollY);
            buttonDrawable.draw(canvas);
            canvas.translate(-scrollX, -scrollY);
        }
    }
}
 
Example 14
Source File: TaskLaunchParamsModifier.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Tries to set task's bound in a way that it won't collide with any other task. By colliding
 * we mean that two tasks have left-top corner very close to each other, so one might get
 * obfuscated by the other one.
 */
@Override
public int onCalculate(TaskRecord task, ActivityInfo.WindowLayout layout,
                       ActivityRecord activity, ActivityRecord source, ActivityOptions options,
                       LaunchParams currentParams, LaunchParams outParams) {
    // We can only apply positioning if we're in a freeform stack.
    if (task == null || task.getStack() == null || !task.inFreeformWindowingMode()) {
        return RESULT_SKIP;
    }

    final ArrayList<TaskRecord> tasks = task.getStack().getAllTasks();

    mAvailableRect.set(task.getParent().getBounds());

    final Rect resultBounds = outParams.mBounds;

    if (layout == null) {
        positionCenter(tasks, mAvailableRect, getFreeformWidth(mAvailableRect),
                getFreeformHeight(mAvailableRect), resultBounds);
        return RESULT_CONTINUE;
    }

    int width = getFinalWidth(layout, mAvailableRect);
    int height = getFinalHeight(layout, mAvailableRect);
    int verticalGravity = layout.gravity & Gravity.VERTICAL_GRAVITY_MASK;
    int horizontalGravity = layout.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    if (verticalGravity == Gravity.TOP) {
        if (horizontalGravity == Gravity.RIGHT) {
            positionTopRight(tasks, mAvailableRect, width, height, resultBounds);
        } else {
            positionTopLeft(tasks, mAvailableRect, width, height, resultBounds);
        }
    } else if (verticalGravity == Gravity.BOTTOM) {
        if (horizontalGravity == Gravity.RIGHT) {
            positionBottomRight(tasks, mAvailableRect, width, height, resultBounds);
        } else {
            positionBottomLeft(tasks, mAvailableRect, width, height, resultBounds);
        }
    } else {
        // Some fancy gravity setting that we don't support yet. We just put the activity in the
        // center.
        Slog.w(TAG, "Received unsupported gravity: " + layout.gravity
                + ", positioning in the center instead.");
        positionCenter(tasks, mAvailableRect, width, height, resultBounds);
    }

    return RESULT_CONTINUE;
}
 
Example 15
Source File: CornerLabelActivity.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
@OnClick({R.id.btn_color, R.id.btn_left, R.id.btn_top, R.id.btn_triangle,
        R.id.btn_text1_minus, R.id.btn_text1_plus, R.id.btn_height1_minus, R.id.btn_height1_plus,
        R.id.btn_text2_minus, R.id.btn_text2_plus, R.id.btn_height2_minus, R.id.btn_height2_plus})
@Override
public void onClick(View v) {
    super.onClick(v);
    switch (v.getId()) {
        case R.id.btn_color:
            labelView.setFillColor(0xff000000 | RandomUtils.getRandom(0, 0xffffff));
            break;
        case R.id.btn_left:
            if (mIsLeft) {
                labelView.right();
            } else {
                labelView.left();
            }
            mIsLeft = !mIsLeft;
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) labelView.getLayoutParams();
            lp.gravity = (mIsLeft ? Gravity.LEFT : Gravity.RIGHT) | (mIsTop ? Gravity.TOP : Gravity.BOTTOM);
            labelView.setLayoutParams(lp);
            break;
        case R.id.btn_top:
            if (mIsTop) {
                labelView.bottom();
            } else {
                labelView.top();
            }
            mIsTop = !mIsTop;
            FrameLayout.LayoutParams lp2 = (FrameLayout.LayoutParams) labelView.getLayoutParams();
            lp2.gravity = (mIsLeft ? Gravity.LEFT : Gravity.RIGHT) | (mIsTop ? Gravity.TOP : Gravity.BOTTOM);
            labelView.setLayoutParams(lp2);
            break;
        case R.id.btn_triangle:
            mIsTriangle = !mIsTriangle;
            labelView.triangle(mIsTriangle);
            break;
        case R.id.btn_text1_minus:
            mText1Index = (mText1Index - 1 + TEXTS.length) % TEXTS.length;
            labelView.setText1(TEXTS[mText1Index]);
            break;
        case R.id.btn_text1_plus:
            mText1Index = (mText1Index + 1) % TEXTS.length;
            labelView.setText1(TEXTS[mText1Index]);
            break;
        case R.id.btn_height1_minus:
            if (mText1Height < 8) break;
            mText1Height -= 2;
            convertPx = SizeUtils.spConvertPx(mText1Height);
            labelView.setTextHeight1(convertPx);
            labelView.setPaddingTop(convertPx);
            labelView.setPaddingCenter(convertPx / 3);
            labelView.setPaddingBottom(convertPx / 3);
            break;
        case R.id.btn_height1_plus:
            if (mText1Height > 30) break;
            mText1Height += 2;
            convertPx = SizeUtils.spConvertPx(mText1Height);
            labelView.setTextHeight1(convertPx);
            labelView.setPaddingTop(convertPx);
            labelView.setPaddingCenter(convertPx / 3);
            labelView.setPaddingBottom(convertPx / 3);
            break;
        case R.id.btn_text2_minus:
            mText2Index = (mText2Index + 5 - 1) % 5;
            labelView.setText2("1234567890".substring(0, mText2Index));
            break;
        case R.id.btn_text2_plus:
            mText2Index = (mText2Index + 5 + 1) % 5;
            labelView.setText2("1234567890".substring(0, mText2Index));
            break;
        case R.id.btn_height2_minus:
            if (mText2Height < 4) break;
            mText2Height -= 2;
            convertPx = SizeUtils.spConvertPx(mText2Height);
            labelView.setTextHeight2(convertPx);
            break;
        case R.id.btn_height2_plus:
            if (mText2Height > 20) break;
            mText2Height += 2;
            convertPx = SizeUtils.spConvertPx(mText2Height);
            labelView.setTextHeight2(convertPx);
            break;
    }
}
 
Example 16
Source File: ExpandableSelectorAnimator.java    From ExpandableSelector with Apache License 2.0 4 votes vote down vote up
private void changeGravityToBottomCenterHorizontal(View view) {
  ((FrameLayout.LayoutParams) view.getLayoutParams()).gravity =
      Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
}
 
Example 17
Source File: EasyTabsBuilder.java    From EasyTabs with MIT License 4 votes vote down vote up
public EasyTabsBuilder changeIconPosition(String position){
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    switch (position) {
        case "left":
            lp.gravity = Gravity.LEFT;
            lp.setMargins(0,0, 0, 2);
            break;
        case "right":
            lp.gravity = Gravity.RIGHT;
            lp.setMargins(0, 2, 0, 0);
            break;
        case "top":
            lp.gravity = Gravity.TOP;
            lp.setMargins(2, 0, 0, 0);
            break;
        case "bottom":
            lp.gravity = Gravity.BOTTOM;
            lp.setMargins(0, 0, 2, 0);
            break;
        case "center":
            lp.gravity = Gravity.CENTER;
            lp.setMargins(0, 0, 0, 0);
            break;
        default:
            break;
    }
    ViewGroup vg = (ViewGroup) StaticTabsLayout.getChildAt(0);
    int tabsCount = vg.getChildCount();
    for (int j = 0; j < tabsCount; j++) {
        ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
        int tabChildsCount = vgTab.getChildCount();
        for (int i = 0; i < tabChildsCount; i++) {
            View tabViewChild = vgTab.getChildAt(i);

            if (tabViewChild instanceof ImageView) {
                tabViewChild.setLayoutParams(lp);
            }
        }
    }
    return this;
}
 
Example 18
Source File: TrashView.java    From dingo with GNU General Public License v3.0 4 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param context Context
 */
TrashView(Context context) {
    super(context);
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mMetrics = new DisplayMetrics();
    mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
    mAnimationHandler = new AnimationHandler(this);
    mIsEnabled = true;

    mParams = new WindowManager.LayoutParams();
    mParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    mParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    mParams.type = OVERLAY_TYPE;
    mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    mParams.format = PixelFormat.TRANSLUCENT;
    // INFO:Windowの原点のみ左下に設定
    mParams.gravity = Gravity.LEFT | Gravity.BOTTOM;

    // 各種Viewの設定
    // TrashViewに直接貼り付けられるView(このViewを介さないと、削除Viewと背景Viewのレイアウトがなぜか崩れる)
    mRootView = new FrameLayout(context);
    mRootView.setClipChildren(false);
    // 削除アイコンのルートView
    mTrashIconRootView = new FrameLayout(context);
    mTrashIconRootView.setClipChildren(false);
    mFixedTrashIconView = new ImageView(context);
    mActionTrashIconView = new ImageView(context);
    // 背景View
    mBackgroundView = new FrameLayout(context);
    mBackgroundView.setAlpha(0.0f);
    final GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{0x00000000, 0x50000000});
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        //noinspection deprecation
        mBackgroundView.setBackgroundDrawable(gradientDrawable);
    } else {
        mBackgroundView.setBackground(gradientDrawable);
    }

    // 背景Viewの貼り付け
    final LayoutParams backgroundParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (BACKGROUND_HEIGHT * mMetrics.density));
    backgroundParams.gravity = Gravity.BOTTOM;
    mRootView.addView(mBackgroundView, backgroundParams);
    // アクションアイコンの貼り付け
    final LayoutParams actionTrashIconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    actionTrashIconParams.gravity = Gravity.CENTER;
    mTrashIconRootView.addView(mActionTrashIconView, actionTrashIconParams);
    // 固定アイコンの貼付け
    final LayoutParams fixedTrashIconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    fixedTrashIconParams.gravity = Gravity.CENTER;
    mTrashIconRootView.addView(mFixedTrashIconView, fixedTrashIconParams);
    // 削除アイコンの貼り付け
    final LayoutParams trashIconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    trashIconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    mRootView.addView(mTrashIconRootView, trashIconParams);

    // TrashViewに貼り付け
    addView(mRootView);

    // 初回描画処理用
    getViewTreeObserver().addOnPreDrawListener(this);
}
 
Example 19
Source File: PagerTitleStrip.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
void updateTextPositions(int position, float positionOffset, boolean force) {
    if (position != mLastKnownCurrentPage) {
        updateText(position, mPager.getAdapter());
    } else if (!force && positionOffset == mLastKnownPositionOffset) {
        return;
    }

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = currWidth / 2;

    final int stripWidth = getWidth();
    final int stripHeight = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    final int textPaddedLeft = paddingLeft + halfCurrWidth;
    final int textPaddedRight = paddingRight + halfCurrWidth;
    final int contentWidth = stripWidth - textPaddedLeft - textPaddedRight;

    float currOffset = positionOffset + 0.5f;
    if (currOffset > 1.f) {
        currOffset -= 1.f;
    }
    final int currCenter = stripWidth - textPaddedRight - (int) (contentWidth * currOffset);
    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    final int prevBaseline = mPrevText.getBaseline();
    final int currBaseline = mCurrText.getBaseline();
    final int nextBaseline = mNextText.getBaseline();
    final int maxBaseline = Math.max(Math.max(prevBaseline, currBaseline), nextBaseline);
    final int prevTopOffset = maxBaseline - prevBaseline;
    final int currTopOffset = maxBaseline - currBaseline;
    final int nextTopOffset = maxBaseline - nextBaseline;
    final int alignedPrevHeight = prevTopOffset + mPrevText.getMeasuredHeight();
    final int alignedCurrHeight = currTopOffset + mCurrText.getMeasuredHeight();
    final int alignedNextHeight = nextTopOffset + mNextText.getMeasuredHeight();
    final int maxTextHeight = Math.max(Math.max(alignedPrevHeight, alignedCurrHeight),
            alignedNextHeight);

    final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int prevTop;
    int currTop;
    int nextTop;
    switch (vgrav) {
        default:
        case Gravity.TOP:
            prevTop = paddingTop + prevTopOffset;
            currTop = paddingTop + currTopOffset;
            nextTop = paddingTop + nextTopOffset;
            break;
        case Gravity.CENTER_VERTICAL:
            final int paddedHeight = stripHeight - paddingTop - paddingBottom;
            final int centeredTop = (paddedHeight - maxTextHeight) / 2;
            prevTop = centeredTop + prevTopOffset;
            currTop = centeredTop + currTopOffset;
            nextTop = centeredTop + nextTopOffset;
            break;
        case Gravity.BOTTOM:
            final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
            prevTop = bottomGravTop + prevTopOffset;
            currTop = bottomGravTop + currTopOffset;
            nextTop = bottomGravTop + nextTopOffset;
            break;
    }

    mCurrText.layout(currLeft, currTop, currRight,
            currTop + mCurrText.getMeasuredHeight());

    final int prevLeft = Math.min(paddingLeft, currLeft - mScaledTextSpacing - prevWidth);
    mPrevText.layout(prevLeft, prevTop, prevLeft + prevWidth,
            prevTop + mPrevText.getMeasuredHeight());

    final int nextLeft = Math.max(stripWidth - paddingRight - nextWidth,
            currRight + mScaledTextSpacing);
    mNextText.layout(nextLeft, nextTop, nextLeft + nextWidth,
            nextTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
}
 
Example 20
Source File: BottomNavigationBehavior.java    From BottomNavigationBar with MIT License 4 votes vote down vote up
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    layoutParams.gravity = Gravity.BOTTOM;
    return super.onLayoutChild(parent, child, layoutDirection);
}