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

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

源代码1 项目: android_9.0.0_r45   文件: FrameLayout.java
/**
 * Describes how the foreground is positioned. Defaults to START and TOP.
 *
 * @param foregroundGravity See {@link android.view.Gravity}
 *
 * @see #getForegroundGravity()
 *
 * @attr ref android.R.styleable#View_foregroundGravity
 */
@android.view.RemotableViewMethod
public void setForegroundGravity(int foregroundGravity) {
    if (getForegroundGravity() != foregroundGravity) {
        super.setForegroundGravity(foregroundGravity);

        // calling get* again here because the set above may apply default constraints
        final Drawable foreground = getForeground();
        if (getForegroundGravity() == Gravity.FILL && foreground != null) {
            Rect padding = new Rect();
            if (foreground.getPadding(padding)) {
                mForegroundPaddingLeft = padding.left;
                mForegroundPaddingTop = padding.top;
                mForegroundPaddingRight = padding.right;
                mForegroundPaddingBottom = padding.bottom;
            }
        } else {
            mForegroundPaddingLeft = 0;
            mForegroundPaddingTop = 0;
            mForegroundPaddingRight = 0;
            mForegroundPaddingBottom = 0;
        }

        requestLayout();
    }
}
 
源代码2 项目: VideoOS-Android-SDK   文件: ForegroundDelegate.java
public void setForegroundGravity(View view, int foregroundGravity) {
    if (view != null) {
        if (mForegroundGravity != foregroundGravity) {
            if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
                foregroundGravity |= Gravity.START;
            }

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

            mForegroundGravity = foregroundGravity;

            if (mForegroundGravity == Gravity.FILL && mForeground != null) {
                Rect padding = new Rect();
                mForeground.getPadding(padding);
            }

            view.requestLayout();
        }
    }
}
 
源代码3 项目: YCCardView   文件: ShadowView.java
@Override
public void setForeground(Drawable foreground) {
    if (foregroundDrawable != null) {
        foregroundDrawable.setCallback(null);
        unscheduleDrawable(foregroundDrawable);
    }
    foregroundDrawable = foreground;

    updateForegroundColor();

    if (foreground != null) {
        setWillNotDraw(false);
        foreground.setCallback(this);
        if (foreground.isStateful()) {
            foreground.setState(getDrawableState());
        }
        if (foregroundDrawGravity == Gravity.FILL) {
            Rect padding = new Rect();
            foreground.getPadding(padding);
        }
    }
    requestLayout();
    invalidate();
}
 
源代码4 项目: YCCardView   文件: ShadowView.java
@Override
public void setForegroundGravity(int foregroundGravity) {
    if (foregroundDrawGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity = foregroundGravity | Gravity.START;
        }
        if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            foregroundGravity = foregroundGravity | Gravity.TOP;
        }
        foregroundDrawGravity = foregroundGravity;
        if (foregroundDrawGravity == Gravity.FILL && foregroundDrawable != null) {
            Rect padding = new Rect();
            foregroundDrawable.getPadding(padding);
        }
        requestLayout();
    }
}
 
源代码5 项目: VerticalTabLayout   文件: VerticalTabLayout.java
public VerticalTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mContext = context;
    mTabSelectedListeners = new ArrayList<>();
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.VerticalTabLayout);
    mColorIndicator = typedArray.getColor(R.styleable.VerticalTabLayout_indicator_color,
            context.getResources().getColor(R.color.colorAccent));
    mIndicatorWidth = (int) typedArray.getDimension(R.styleable.VerticalTabLayout_indicator_width, DisplayUtil.dp2px(context, 3));
    mIndicatorCorners = typedArray.getDimension(R.styleable.VerticalTabLayout_indicator_corners, 0);
    mIndicatorGravity = typedArray.getInteger(R.styleable.VerticalTabLayout_indicator_gravity, Gravity.LEFT);
    if (mIndicatorGravity == 3) {
        mIndicatorGravity = Gravity.LEFT;
    } else if (mIndicatorGravity == 5) {
        mIndicatorGravity = Gravity.RIGHT;
    } else if (mIndicatorGravity == 119) {
        mIndicatorGravity = Gravity.FILL;
    }
    mTabMargin = (int) typedArray.getDimension(R.styleable.VerticalTabLayout_tab_margin, 0);
    mTabMode = typedArray.getInteger(R.styleable.VerticalTabLayout_tab_mode, TAB_MODE_FIXED);
    int defaultTabHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
    mTabHeight = (int) typedArray.getDimension(R.styleable.VerticalTabLayout_tab_height, defaultTabHeight);
    typedArray.recycle();
}
 
源代码6 项目: ForegroundViews   文件: ForegroundDelegate.java
public void setForegroundGravity(int foregroundGravity) {
    if (mForegroundGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity.START;
        }

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

        mForegroundGravity = foregroundGravity;


        if (mForegroundGravity == Gravity.FILL && mForeground != null) {
            Rect padding = new Rect();
            mForeground.getPadding(padding);
        }

        mView.requestLayout();
    }
}
 
源代码7 项目: RetailStore   文件: ForegroundLinearLayout.java
/**
 * Describes how the foreground is positioned. Defaults to START and TOP.
 *
 * @param foregroundGravity See {@link Gravity}
 *
 * @see #getForegroundGravity()
 */
public void setForegroundGravity(int foregroundGravity) {
    if (mForegroundGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity.START;
        }

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

        mForegroundGravity = foregroundGravity;


        if (mForegroundGravity == Gravity.FILL && mForeground != null) {
            Rect padding = new Rect();
            mForeground.getPadding(padding);
        }

        requestLayout();
    }
}
 
源代码8 项目: X-Alarm   文件: WheelView.java
/**
 * Describes how the foreground is positioned. Defaults to START and TOP.
 *
 * @param foregroundGravity See {@link android.view.Gravity}
 *
 * @see #getForegroundGravity()
 */
public void setForegroundGravity(int foregroundGravity) {
    if (mForegroundGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity.START;
        }

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

        mForegroundGravity = foregroundGravity;


        if (mForegroundGravity == Gravity.FILL && mWheelForeground != null) {
            Rect padding = new Rect();
            mWheelForeground.getPadding(padding);
        }

        requestLayout();
    }
}
 
源代码9 项目: pandora   文件: TextViewParser.java
private static String gravityToStr(int gravity) {
    switch (gravity) {
        case Gravity.NO_GRAVITY:
            return "NO_GRAVITY";
        case Gravity.LEFT:
            return "LEFT";
        case Gravity.TOP:
            return "TOP";
        case Gravity.RIGHT:
            return "RIGHT";
        case Gravity.BOTTOM:
            return "BOTTOM";
        case Gravity.CENTER:
            return "CENTER";
        case Gravity.CENTER_HORIZONTAL:
            return "CENTER_HORIZONTAL";
        case Gravity.CENTER_VERTICAL:
            return "CENTER_VERTICAL";
        case Gravity.START:
            return "START";
        case Gravity.END:
            return "END";
        case Gravity.CLIP_HORIZONTAL:
            return "CLIP_HORIZONTAL";
        case Gravity.CLIP_VERTICAL:
            return "CLIP_VERTICAL";
        case Gravity.FILL:
            return "FILL";
        case Gravity.FILL_HORIZONTAL:
            return "FILL_HORIZONTAL";
        case Gravity.FILL_VERTICAL:
            return "FILL_VERTICAL";
        default:
            return "OTHER";
    }
}
 
源代码10 项目: Mizuu   文件: ForegroundLinearLayout.java
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in the frame layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(Drawable drawable) {
    if (mForeground != drawable) {
        if (mForeground != null) {
            mForeground.setCallback(null);
            unscheduleDrawable(mForeground);
        }

        mForeground = drawable;

        if (drawable != null) {
            setWillNotDraw(false);
            drawable.setCallback(this);
            if (drawable.isStateful()) {
                drawable.setState(getDrawableState());
            }
            if (mForegroundGravity == Gravity.FILL) {
                Rect padding = new Rect();
                drawable.getPadding(padding);
            }
        }  else {
            setWillNotDraw(true);
        }
        requestLayout();
        invalidate();
    }
}
 
源代码11 项目: VideoOS-Android-SDK   文件: ForegroundDelegate.java
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in the frame layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(View view, Drawable drawable) {
    if (view != null) {
        if (mForeground != drawable) {
            if (mForeground != null) {
                mForeground.setCallback(null);
                view.unscheduleDrawable(mForeground);
            }

            mForeground = drawable;

            if (drawable != null) {
                view.setWillNotDraw(false);
                drawable.setCallback(view);
                if (drawable.isStateful()) {
                    drawable.setState(view.getDrawableState());
                }
                if (mForegroundGravity == Gravity.FILL) {
                    Rect padding = new Rect();
                    drawable.getPadding(padding);
                }

                //update bounds
                updateBounds(view, drawable);//added by song
            } else {
                view.setWillNotDraw(true);
            }
            view.requestLayout();
            view.invalidate();
        }
    }
}
 
源代码12 项目: tns-core-modules-widgets   文件: LayoutBase.java
protected static int getGravity(View view) {
	int gravity = -1;
	LayoutParams params = view.getLayoutParams();
	if (params instanceof FrameLayout.LayoutParams) {
		gravity = ((FrameLayout.LayoutParams)params).gravity;	
	}
        
       if (gravity == -1) {
           gravity = Gravity.FILL;
       }
       
       return gravity;
}
 
源代码13 项目: Mover   文件: FrameLayoutCompat.java
/**
 * Describes how the foreground is positioned. Defaults to START and TOP.
 *
 * @param foregroundGravity See {@link android.view.Gravity}
 *
 * @see #getForegroundGravity()
 *
 * @attr ref android.R.styleable#FrameLayout_foregroundGravity
 */
public void setForegroundGravity(int foregroundGravity) {
    if (mForegroundGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity.START;
        }

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

        mForegroundGravity = foregroundGravity;


        if (mForegroundGravity == Gravity.FILL && mForeground != null) {
            Rect padding = new Rect();
            if (mForeground.getPadding(padding)) {
                mForegroundPaddingLeft = padding.left;
                mForegroundPaddingTop = padding.top;
                mForegroundPaddingRight = padding.right;
                mForegroundPaddingBottom = padding.bottom;
            }
        } else {
            mForegroundPaddingLeft = 0;
            mForegroundPaddingTop = 0;
            mForegroundPaddingRight = 0;
            mForegroundPaddingBottom = 0;
        }

        requestLayout();
    }
}
 
源代码14 项目: ForegroundViews   文件: ForegroundDelegate.java
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in the frame layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(@Nullable Drawable drawable) {
    if (mForeground != drawable) {
        if (mForeground != null) {
            mForeground.setCallback(null);
            mView.unscheduleDrawable(mForeground);
        }

        mForeground = drawable;

        if (drawable != null) {
            mView.setWillNotDraw(false);
            drawable.setCallback(mView);
            if (drawable.isStateful()) {
                drawable.setState(mView.getDrawableState());
            }
            if (mForegroundGravity == Gravity.FILL) {
                Rect padding = new Rect();
                drawable.getPadding(padding);
            }
        }  else {
            mView.setWillNotDraw(true);
        }
        mView.requestLayout();
        mView.invalidate();
    }
}
 
/**
 * Supply a Drawable that is to be rendered on top of all of the child views in the frame layout.
 * Any padding in the Drawable will be taken into account by ensuring that the children are inset
 * to be placed inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
@Override
public void setForeground(@Nullable Drawable drawable) {
  if (foreground != drawable) {
    if (foreground != null) {
      foreground.setCallback(null);
      unscheduleDrawable(foreground);
    }

    foreground = drawable;

    if (drawable != null) {
      setWillNotDraw(false);
      drawable.setCallback(this);
      if (drawable.isStateful()) {
        drawable.setState(getDrawableState());
      }
      if (foregroundGravity == Gravity.FILL) {
        Rect padding = new Rect();
        drawable.getPadding(padding);
      }
    } else {
      setWillNotDraw(true);
    }
    requestLayout();
    invalidate();
  }
}
 
源代码16 项目: android-proguards   文件: ForegroundLinearLayout.java
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in this layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(Drawable drawable) {
    if (mForeground != drawable) {
        if (mForeground != null) {
            mForeground.setCallback(null);
            unscheduleDrawable(mForeground);
        }

        mForeground = drawable;

        if (drawable != null) {
            setWillNotDraw(false);
            drawable.setCallback(this);
            if (drawable.isStateful()) {
                drawable.setState(getDrawableState());
            }
            if (mForegroundGravity == Gravity.FILL) {
                Rect padding = new Rect();
                drawable.getPadding(padding);
            }
        } else {
            setWillNotDraw(true);
        }
        requestLayout();
        invalidate();
    }
}
 
/**
 * Supply a Drawable that is to be rendered on top of all of the child
 * views in the frame layout.  Any padding in the Drawable will be taken
 * into account by ensuring that the children are inset to be placed
 * inside of the padding area.
 *
 * @param drawable The Drawable to be drawn on top of the children.
 */
public void setForeground(Drawable drawable) {
    if (mForeground != drawable) {
        if (mForeground != null) {
            mForeground.setCallback(null);
            unscheduleDrawable(mForeground);
        }

        mForeground = drawable;

        if (drawable != null) {
            setWillNotDraw(false);
            drawable.setCallback(this);
            if (drawable.isStateful()) {
                drawable.setState(getDrawableState());
            }
            if (mForegroundGravity == Gravity.FILL) {
                Rect padding = new Rect();
                drawable.getPadding(padding);
            }
        } else {
            setWillNotDraw(true);
        }
        requestLayout();
        invalidate();
    }
}
 
源代码18 项目: Rhythm   文件: SimpleArgumentsBundle.java
/**
 * {@inheritDoc} Does a quick and rough parsing of the raw string for containing constant words like
 * <code>top</code> or <code>center_vertical</code>
 */
@Override
@SuppressLint("RtlHardcoded")
public int getGravity(String key, int defaultValue) {
    String gravityArg = resolveArgument(key);
    if (gravityArg == null) {
        return defaultValue;
    } else if (gravityArg.equals("center")) {
        return Gravity.CENTER;
    } else if (gravityArg.equals("fill")) {
        return Gravity.FILL;
    } else {
        // supported options
        int gravity = 0;
        if (gravityArg.contains("top")) {
            gravity |= Gravity.TOP;
        }
        if (gravityArg.contains("bottom")) {
            gravity |= Gravity.BOTTOM;
        }
        if (gravityArg.contains("center_vertical")) {
            gravity |= Gravity.CENTER_VERTICAL;
        }
        if (gravityArg.contains("fill_vertical")) {
            gravity |= Gravity.FILL_VERTICAL;
        }
        if (gravityArg.contains("left")) {
            gravity |= Gravity.LEFT;
        }
        if (gravityArg.contains("right")) {
            gravity |= Gravity.RIGHT;
        }
        if (gravityArg.contains("center_horizontal")) {
            gravity |= Gravity.CENTER_HORIZONTAL;
        }
        if (gravityArg.contains("fill_horizontal")) {
            gravity |= Gravity.FILL_HORIZONTAL;
        }
        return gravity;
    }
}
 
源代码19 项目: ProjectX   文件: TagTabStrip.java
@SuppressLint("RtlHardcoded")
private void applyGravity(int itemWidth, int itemHeight) {
    final int count = mCount;
    if (count == 0) {
        mFirstCenterX = 0;
        mFirstCenterY = 0;
        mItemCenterOffset = 0;
        return;
    }
    final int padding = mPadding;
    final float scale = mScale > 1 ? mScale : 1;
    final int paddingStart = ViewCompat.getPaddingStart(this);
    final int paddingEnd = ViewCompat.getPaddingEnd(this);
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    final int contentWidth = width - paddingStart - paddingEnd;
    final int contentHeight = height - paddingTop - paddingBottom;
    mItemCenterOffset = itemWidth + padding;
    switch (GravityCompat.getAbsoluteGravity(mGravity,
            ViewCompat.getLayoutDirection(this))) {
        case Gravity.LEFT:
        case Gravity.TOP:
        case Gravity.LEFT | Gravity.TOP:
            mFirstCenterX = paddingStart + itemWidth * scale * 0.5f;
            mFirstCenterY = paddingTop + itemHeight * scale * 0.5f;
            break;
        case Gravity.CENTER_HORIZONTAL:
        case Gravity.CENTER_HORIZONTAL | Gravity.TOP:
            mFirstCenterX = paddingStart + contentWidth * 0.5f -
                    mItemCenterOffset * (count - 1) * 0.5f;
            mFirstCenterY = paddingTop + itemHeight * scale * 0.5f;
            break;
        case Gravity.RIGHT:
        case Gravity.RIGHT | Gravity.TOP:
            mFirstCenterX = width - paddingEnd - itemWidth * scale * 0.5f -
                    mItemCenterOffset * (count - 1);
            mFirstCenterY = paddingTop + itemHeight * scale * 0.5f;
            break;
        case Gravity.CENTER_VERTICAL:
        case Gravity.CENTER_VERTICAL | Gravity.LEFT:
            mFirstCenterX = paddingStart + itemWidth * scale * 0.5f;
            mFirstCenterY = paddingTop + contentHeight * 0.5f;
            break;
        default:
        case Gravity.CENTER:
            mFirstCenterX = paddingStart + contentWidth * 0.5f -
                    mItemCenterOffset * (count - 1) * 0.5f;
            mFirstCenterY = paddingTop + contentHeight * 0.5f;
            break;
        case Gravity.CENTER_VERTICAL | Gravity.RIGHT:
            mFirstCenterX = width - paddingEnd - itemWidth * scale * 0.5f -
                    mItemCenterOffset * (count - 1);
            mFirstCenterY = paddingTop + contentHeight * 0.5f;
            break;
        case Gravity.BOTTOM:
        case Gravity.BOTTOM | Gravity.LEFT:
            mFirstCenterX = paddingStart + itemWidth * scale * 0.5f;
            mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f;
            break;
        case Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM:
            mFirstCenterX = paddingStart + contentWidth * 0.5f -
                    mItemCenterOffset * (count - 1) * 0.5f;
            mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f;
            break;
        case Gravity.RIGHT | Gravity.BOTTOM:
            mFirstCenterX = width - paddingEnd - itemWidth * scale * 0.5f -
                    mItemCenterOffset * (count - 1);
            mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f;
            break;
        // 水平方向上沾满
        case Gravity.FILL:
            mItemCenterOffset = count == 1 ? 0 :
                    (contentWidth - itemWidth * scale) / (count - 1);
            mFirstCenterX = paddingStart + itemWidth * scale * 0.5f;
            mFirstCenterY = paddingTop + contentHeight * 0.5f;
            break;
        case Gravity.FILL_HORIZONTAL:
        case Gravity.FILL_HORIZONTAL | Gravity.TOP:
            mItemCenterOffset = count == 1 ? 0 :
                    (contentWidth - itemWidth * scale) / (count - 1);
            mFirstCenterX = paddingStart + itemWidth * scale * 0.5f;
            mFirstCenterY = paddingTop + itemHeight * scale * 0.5f;
            break;
        case Gravity.FILL_HORIZONTAL | Gravity.BOTTOM:
            mItemCenterOffset = count == 1 ? 0 :
                    (contentWidth - itemWidth * scale) / (count - 1);
            mFirstCenterX = paddingStart + itemWidth * scale * 0.5f;
            mFirstCenterY = height - paddingBottom - itemHeight * scale * 0.5f;
            break;
    }
}
 
public CommonLayoutParams() {
    super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.FILL);
}