下面列出了android.view.View#getPaddingBottom ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void autoPadding(View view)
{
Object tag = view.getTag(R.id.id_tag_autolayout_padding);
if (tag != null) return;
view.setTag(R.id.id_tag_autolayout_padding, "Just Identify");
int l = view.getPaddingLeft();
int t = view.getPaddingTop();
int r = view.getPaddingRight();
int b = view.getPaddingBottom();
l = getPercentWidthSize(l);
t = getPercentHeightSize(t);
r = getPercentWidthSize(r);
b = getPercentHeightSize(b);
view.setPadding(l, t, r, b);
}
public SmartViewHolder(View itemView, AdapterView.OnItemClickListener mListener) {
super(itemView);
this.mListener = mListener;
itemView.setOnClickListener(this);
/*
* 设置水波纹背景
*/
if (itemView.getBackground() == null) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = itemView.getContext().getTheme();
int top = itemView.getPaddingTop();
int bottom = itemView.getPaddingBottom();
int left = itemView.getPaddingLeft();
int right = itemView.getPaddingRight();
if (theme.resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true)) {
itemView.setBackgroundResource(typedValue.resourceId);
}
itemView.setPadding(left, top, right, bottom);
}
}
/**
* apply padding in view
*/
public static void applyPadding(View view, DynamicProperty property, int position) {
if (view != null) {
switch (property.type) {
case DIMEN: {
int[] padding = new int[] {
view.getPaddingLeft(),
view.getPaddingTop(),
view.getPaddingRight(),
view.getPaddingBottom()
};
padding[position] = property.getValueInt();
view.setPadding(padding[0], padding[1], padding[2], padding[3]);
}
break;
}
}
}
/**
* Fix the bug of 5497 in Android.
* <p>Don't set adjustResize</p>
*
* @param activity The activity.
*/
public static void fixAndroidBug5497(final Activity activity) {
// Window window = activity.getWindow();
// int softInputMode = window.getAttributes().softInputMode;
// window.setSoftInputMode(softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
final FrameLayout contentView = activity.findViewById(android.R.id.content);
final View contentViewChild = contentView.getChildAt(0);
final int paddingBottom = contentViewChild.getPaddingBottom();
sContentViewInvisibleHeightPre5497 = getContentViewInvisibleHeight(activity);
contentView.getViewTreeObserver()
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int height = getContentViewInvisibleHeight(activity);
if (sContentViewInvisibleHeightPre5497 != height) {
contentViewChild.setPadding(
contentViewChild.getPaddingLeft(),
contentViewChild.getPaddingTop(),
contentViewChild.getPaddingRight(),
paddingBottom + getDecorViewInvisibleHeight(activity)
);
sContentViewInvisibleHeightPre5497 = height;
}
}
});
}
@Override
protected void execute(View view, int val)
{
int l = view.getPaddingLeft();
int t = view.getPaddingTop();
int r = val;
int b = view.getPaddingBottom();
view.setPadding(l, t, r, b);
}
public static AnimatorSet InUpRight(View view){
AnimatorSet animatorSet = new AnimatorSet();
float x = view.getWidth() - view.getPaddingRight();
float y = view.getHeight() - view.getPaddingBottom();
ObjectAnimator object1 = ObjectAnimator.ofFloat(view, "rotation", -90, 0);
ObjectAnimator object2 = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
ObjectAnimator object3 = ObjectAnimator.ofFloat(view, "pivotX", x, x);
ObjectAnimator object4 = ObjectAnimator.ofFloat(view, "pivotY", y, y);
animatorSet.playTogether(object1, object2, object3, object4);
return animatorSet;
}
private void initLayout() {
removeAllViews();
if (useTemplate) {
View layout = LayoutInflater.from(mContext).inflate(
R.layout.base_control_template, this, false);
if (withPadding) {
int top_padding = layout.getPaddingTop();
int right_padding = layout.getPaddingRight();
int bottom_padding = layout.getPaddingBottom();
int left_padding = layout.getPaddingLeft();
if (!with_bottom_padding) {
layout.setPadding(left_padding, top_padding, right_padding, 0);
}
if (!with_top_padding) {
layout.setPadding(left_padding, 0, right_padding, bottom_padding);
}
} else {
layout.setPadding(0, 0, 0, 0);
}
addView(layout);
container = (ViewGroup) findViewById(R.id.control_container);
img_icon = (ImageView) findViewById(android.R.id.icon);
img_icon.setColorFilter(tint_color);
setImageIcon();
} else {
container = this;
}
}
@Override
protected void execute(View view, int val) {
int l = view.getPaddingLeft();
int t = view.getPaddingTop();
int r = val;
int b = view.getPaddingBottom();
view.setPadding(l, t, r, b);
}
@Override
public void prepare(View target) {
float x = target.getPaddingLeft();
float y = target.getHeight() - target.getPaddingBottom();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "alpha", 1, 0),
ObjectAnimator.ofFloat(target,"rotation",0,-90),
ObjectAnimator.ofFloat(target,"pivotX",x,x),
ObjectAnimator.ofFloat(target,"pivotY",y,y)
);
}
@Override
public void prepare(View target) {
float x = target.getPaddingLeft();
float y = target.getHeight() - target.getPaddingBottom();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "rotation", -90, 0),
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "pivotX", x, x),
ObjectAnimator.ofFloat(target, "pivotY", y, y)
);
}
@Override
protected void execute(View view, int val) {
int l = val;
int t = view.getPaddingTop();
int r = view.getPaddingRight();
int b = view.getPaddingBottom();
view.setPadding(l, t, r, b);
}
@Override
public void prepare(View target) {
float x = target.getWidth() - target.getPaddingRight();
float y = target.getHeight() - target.getPaddingBottom();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "rotation", 90, 0),
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "pivotX", x, x),
ObjectAnimator.ofFloat(target, "pivotY", y, y)
);
}
@Override
public void prepare(View target) {
float x = target.getPaddingLeft();
float y = target.getHeight() - target.getPaddingBottom();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "rotation", 90, 0),
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "pivotX", x, x),
ObjectAnimator.ofFloat(target, "pivotY", y, y)
);
}
@Override
public void showMoreKeysPanel(final View parentView, final Controller controller,
final int pointX, final int pointY, final KeyboardActionListener listener) {
mController = controller;
mListener = listener;
final View container = getContainerView();
// The coordinates of panel's left-top corner in parentView's coordinate system.
// We need to consider background drawable paddings.
final int x = pointX - getDefaultCoordX() - container.getPaddingLeft() - getPaddingLeft();
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
+ getPaddingBottom();
parentView.getLocationInWindow(mCoordinates);
// Ensure the horizontal position of the panel does not extend past the parentView edges.
final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
final int panelX = Math.max(0, Math.min(maxX, x)) + CoordinateUtils.x(mCoordinates);
final int panelY = y + CoordinateUtils.y(mCoordinates);
container.setX(panelX);
container.setY(panelY);
mOriginX = x + container.getPaddingLeft();
mOriginY = y + container.getPaddingTop();
controller.onShowMoreKeysPanel(this);
final MoreKeysKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
if (accessibilityDelegate != null
&& AccessibilityUtils.Companion.getInstance().isAccessibilityEnabled()) {
accessibilityDelegate.onShowMoreKeysKeyboard();
}
}
@Override
public void prepare(View target) {
float x = target.getWidth() - target.getPaddingRight();
float y = target.getHeight() - target.getPaddingBottom();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "rotation", -90, 0),
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "pivotX", x, x),
ObjectAnimator.ofFloat(target, "pivotY", y, y)
);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), heightMeasureSpec);
if (isLast) {
View parent = (View) getParent();
if (parent != null) {
int height = parent.getMeasuredHeight() - parent.getPaddingBottom() - parent.getPaddingTop() - AndroidUtilities.dp(24);
if (getMeasuredHeight() < height) {
setMeasuredDimension(getMeasuredWidth(), height);
}
}
}
}
@Override
protected void execute(View view, int val)
{
int l = view.getPaddingLeft();
int t = val;
int r = view.getPaddingRight();
int b = view.getPaddingBottom();
view.setPadding(l, t, r, b);
}
public void loadData() {
tvSettingName.setText(selector.getSettingName());
if (selector.getCurrentOptionIndex() >= 0 && selector.getCurrentOptionIndex() < selector
.getOptionCount()) {
tvCurrentOption.setText(selector.getOptionName(selector.getCurrentOptionIndex()));
} else {
tvCurrentOption.setText("");
}
llOptions.removeAllViews();
if (selector != null) {
int count = selector.getOptionCount();
for (int i = 0;
i < count;
i++) {
View v = inflater.inflate(R.layout.list_item_setting_option, null);
llOptions.addView(v, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
TextView tv = (TextView) v.findViewById(R.id.tv_option_name);
TextView tvNote = (TextView) v.findViewById(R.id.tv_option_note);
ImageView iv = (ImageView) v.findViewById(R.id.iv_check);
tv.setText(selector.getOptionName(i));
CharSequence note = selector.getOptionNote(i);
if (note == null || note.length() == 0) {
tvNote.setText("");
} else {
tvNote.setText(note);
}
tvNote.setCompoundDrawablesWithIntrinsicBounds(null, null,
selector.getOptionDrawable(i), null);
if (i == selector.getCurrentOptionIndex()) {
iv.setVisibility(View.VISIBLE);
} else {
iv.setVisibility(View.GONE);
}
v.setOnClickListener(new OptionClick(i));
if (i == count - 1) {
preOptionBottomSpace = v.getPaddingBottom();
v.setPadding(v.getPaddingLeft(), v.getPaddingTop(), v.getPaddingRight(),
preOptionBottomSpace + bottomSpace);
}
}
}
}
/**
* get alignment position relative to optical left/top of itemView.
*/
public int getAlignmentPosition(View itemView) {
LayoutParams p = (LayoutParams) itemView.getLayoutParams();
View view = itemView;
if (mViewId != 0) {
view = itemView.findViewById(mViewId);
if (view == null) {
view = itemView;
}
}
int alignPos;
if (mOrientation == HORIZONTAL) {
if (mOffset >= 0) {
alignPos = mOffset;
if (mOffsetWithPadding) {
alignPos += view.getPaddingLeft();
}
} else {
alignPos = view == itemView ? p.getOpticalWidth(view) : view.getWidth()
+ mOffset;
if (mOffsetWithPadding) {
alignPos -= view.getPaddingRight();
}
}
if (mOffsetPercent != ITEM_ALIGN_OFFSET_PERCENT_DISABLED) {
alignPos += ((view == itemView ? p.getOpticalWidth(view) : view.getWidth())
* mOffsetPercent) / 100f;
}
if (itemView != view) {
mRect.left = alignPos;
((ViewGroup) itemView).offsetDescendantRectToMyCoords(view, mRect);
alignPos = mRect.left - p.getOpticalLeftInset();
}
} else {
if (mOffset >= 0) {
alignPos = mOffset;
if (mOffsetWithPadding) {
alignPos += view.getPaddingTop();
}
} else {
alignPos = view == itemView ? p.getOpticalHeight(view) : view.getHeight()
+ mOffset;
if (mOffsetWithPadding) {
alignPos += view.getPaddingBottom();
}
}
if (mOffsetPercent != ITEM_ALIGN_OFFSET_PERCENT_DISABLED) {
alignPos += ((view == itemView ? p.getOpticalHeight(view) : view.getHeight())
* mOffsetPercent) / 100f;
}
if (itemView != view) {
mRect.top = alignPos;
((ViewGroup) itemView).offsetDescendantRectToMyCoords(view, mRect);
alignPos = mRect.top - p.getOpticalTopInset();
}
}
return alignPos;
}
public static MeasureSpec onMeasure(@NonNull final View target,
final double requestedAspect,
@IScaledView.ScaleMode final int scaleMode,
final boolean needResizeToKeepAspect,
final int widthMeasureSpec, final int heightMeasureSpec) {
final MeasureSpec result = new MeasureSpec(widthMeasureSpec, heightMeasureSpec);
// if (DEBUG) Log.v(TAG, "onMeasure:requestedAspect=" + requestedAspect);
// 要求されたアスペクト比が負の時(初期生成時)は何もしない
if ((requestedAspect > 0)
&& (scaleMode == SCALE_MODE_KEEP_ASPECT)
&& needResizeToKeepAspect) {
int initialWidth = View.MeasureSpec.getSize(widthMeasureSpec);
int initialHeight = View.MeasureSpec.getSize(heightMeasureSpec);
final int horizPadding = target.getPaddingLeft() + target.getPaddingRight();
final int vertPadding = target.getPaddingTop() + target.getPaddingBottom();
initialWidth -= horizPadding;
initialHeight -= vertPadding;
final double viewAspectRatio = (double)initialWidth / initialHeight;
final double aspectDiff = requestedAspect / viewAspectRatio - 1;
// 計算誤差が生じる可能性が有るので指定した値との差が小さければそのままにする
if (Math.abs(aspectDiff) > 0.005) {
if (aspectDiff > 0) {
// 幅基準で高さを決める
initialHeight = (int) (initialWidth / requestedAspect);
} else {
// 高さ基準で幅を決める
initialWidth = (int) (initialHeight * requestedAspect);
}
initialWidth += horizPadding;
initialHeight += vertPadding;
result.widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(initialWidth, View.MeasureSpec.EXACTLY);
result.heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(initialHeight, View.MeasureSpec.EXACTLY);
}
}
return result;
}