下面列出了android.view.ViewGroup#getPaddingRight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ViewHolder(View itemView) {
super(itemView);
if (itemView instanceof CanMergeView) {
mCanMergeView = (CanMergeView) itemView;
} else if (itemView instanceof ViewGroup) {
ViewGroup group = (ViewGroup) itemView;
paddingLeft = group.getPaddingLeft();
paddingRight = group.getPaddingRight();
paddingTop = group.getPaddingTop();
paddingBottom = group.getPaddingBottom();
//只遍历一层 寻找第一个符合条件的view
for (int i = 0; i < group.getChildCount(); i++) {
View child = group.getChildAt(i);
if (child instanceof CanMergeView) {
mCanMergeView = (CanMergeView) child;
break;
}
}
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (moveable) {
ViewGroup parentView = ((ViewGroup) getParent());
MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
viewWidth = getRight() - getLeft();
viewHight = getBottom() - getTop();
parentWidth = parentView.getMeasuredWidth();
parentHeight = parentView.getMeasuredHeight();
minLeftMargin = lp.leftMargin;
leftPadding = parentView.getPaddingLeft();
rightDistance = lp.rightMargin + parentView.getPaddingRight();
maxLeftMargin = parentWidth - rightDistance - viewWidth - leftPadding;
minTopMargin = lp.topMargin;
topPadding = parentView.getPaddingTop();
bottomDistance = lp.bottomMargin + parentView.getPaddingBottom();
maxTopMargin = parentHeight - bottomDistance - viewHight - topPadding;
}
}
@Override
public void layoutDecorated(@NonNull View child, int left, int top, int right, int bottom) {
if (!mCenter) {
super.layoutDecorated(child, left, top, right, bottom);
return;
}
final int leftDecorationWidth = getLeftDecorationWidth(child);
final int topDecorationHeight = getTopDecorationHeight(child);
final int rightDecorationWidth = getRightDecorationWidth(child);
final int bottomDecorationHeight = getBottomDecorationHeight(child);
final ViewGroup parent = (ViewGroup) child.getParent();
final int offset;
if (getOrientation() == HORIZONTAL) {
final int contentHeight = parent.getMeasuredHeight() -
parent.getPaddingTop() - parent.getPaddingBottom();
offset = (contentHeight - (bottom - top)) / 2;
child.layout(left + leftDecorationWidth, top + topDecorationHeight + offset,
right - rightDecorationWidth, bottom - bottomDecorationHeight + offset);
} else {
final int contentWidth = parent.getMeasuredWidth() -
parent.getPaddingLeft() - parent.getPaddingRight();
offset = (contentWidth - (right - left)) / 2;
child.layout(left + leftDecorationWidth + offset, top + topDecorationHeight,
right - rightDecorationWidth + offset, bottom - bottomDecorationHeight);
}
}
static boolean maybeLogLastMountStart(
@Nullable MountStartupLoggingInfo loggingInfo, LithoView lithoView) {
if (loggingInfo != null
&& LithoStartupLogger.isEnabled(loggingInfo.startupLogger)
&& loggingInfo.firstMountLogged != null
&& loggingInfo.firstMountLogged[0]
&& loggingInfo.lastMountLogged != null
&& !loggingInfo.lastMountLogged[0]) {
final ViewGroup parent = (ViewGroup) lithoView.getParent();
if (parent == null) {
return false;
}
if (loggingInfo.isLastAdapterItem
|| (loggingInfo.isOrientationVertical
? lithoView.getBottom() >= parent.getHeight() - parent.getPaddingBottom()
: lithoView.getRight() >= parent.getWidth() - parent.getPaddingRight())) {
loggingInfo.startupLogger.markPoint(
LithoStartupLogger.LAST_MOUNT,
LithoStartupLogger.START,
loggingInfo.startupLoggerAttribution);
return true;
}
}
return false;
}
private static void AdjustRightToOutOfBounds(TextView tipView, ViewGroup root, Point point, RxCoordinates anchorViewRxCoordinates, RxCoordinates rootLocation) {
ViewGroup.LayoutParams params = tipView.getLayoutParams();
int availableSpace = rootLocation.right - root.getPaddingRight() - anchorViewRxCoordinates.right;
if (point.x + tipView.getMeasuredWidth() > rootLocation.right - root.getPaddingRight()){
params.width = availableSpace;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
tipView.setLayoutParams(params);
measureViewWithFixedWidth(tipView, params.width);
}
}
private static void AdjustHorizontalLeftAlignmentOutOfBounds(TextView tipView, ViewGroup root,
Point point, RxCoordinates anchorViewRxCoordinates,
RxCoordinates rootLocation) {
ViewGroup.LayoutParams params = tipView.getLayoutParams();
int rootRight = rootLocation.right - root.getPaddingRight();
if (point.x + tipView.getMeasuredWidth() > rootRight){
params.width = rootRight - anchorViewRxCoordinates.left;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
tipView.setLayoutParams(params);
measureViewWithFixedWidth(tipView, params.width);
}
}
private static void AdjustHorizontalCenteredOutOfBounds(TextView tipView, ViewGroup root,
Point point, RxCoordinates rootLocation) {
ViewGroup.LayoutParams params = tipView.getLayoutParams();
int rootWidth = root.getWidth() - root.getPaddingLeft() - root.getPaddingRight();
if (tipView.getMeasuredWidth() > rootWidth) {
point.x = rootLocation.left + root.getPaddingLeft();
params.width = rootWidth;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
tipView.setLayoutParams(params);
measureViewWithFixedWidth(tipView, rootWidth);
}
}
/**
* 调整位置Padding
* @param parent
* @param background
*/
private void setViewPadding(ViewGroup parent, int background) {
int[] rect = new int[4];
rect[0] = parent.getPaddingLeft();
rect[1] = parent.getPaddingTop();
rect[2] = parent.getPaddingRight();
rect[3] = parent.getPaddingBottom();
parent.setBackgroundResource(background);
parent.setPadding(rect[0], rect[1], rect[2], rect[3]);
}
/**
* Get the x position for the preview view. This method takes into account padding
* that'll make the frame not move until the scrub position exceeds
* at least half of the frame's width.
*/
private int updatePreviewX(int progress, int max) {
if (max == 0) {
return 0;
}
final ViewGroup parent = (ViewGroup) previewView.getParent();
final ViewGroup.MarginLayoutParams layoutParams
= (ViewGroup.MarginLayoutParams) previewView.getLayoutParams();
float offset = (float) progress / max;
int minimumX = previewView.getLeft();
int maximumX = parent.getWidth()
- parent.getPaddingRight()
- layoutParams.rightMargin;
float previewPadding = previewBar.getThumbOffset();
float previewLeftX = ((View) previewBar).getLeft();
float previewRightX = ((View) previewBar).getRight();
float previewSeekBarStartX = previewLeftX + previewPadding;
float previewSeekBarEndX = previewRightX - previewPadding;
float currentX = previewSeekBarStartX
+ (previewSeekBarEndX - previewSeekBarStartX) * offset;
float startX = currentX - previewView.getWidth() / 2f;
float endX = startX + previewView.getWidth();
// Clamp the moves
if (startX >= minimumX && endX <= maximumX) {
return (int) startX;
} else if (startX < minimumX) {
return minimumX;
} else {
return maximumX - previewView.getWidth();
}
}
@Override
public void layoutDecoratedWithMargins(@NonNull View child, int left, int top, int right, int bottom) {
if (!mCenter) {
super.layoutDecoratedWithMargins(child, left, top, right, bottom);
return;
}
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
final int leftDecorationWidth = getLeftDecorationWidth(child);
final int topDecorationHeight = getTopDecorationHeight(child);
final int rightDecorationWidth = getRightDecorationWidth(child);
final int bottomDecorationHeight = getBottomDecorationHeight(child);
final ViewGroup parent = (ViewGroup) child.getParent();
final int offset;
if (getOrientation() == RecyclerView.HORIZONTAL) {
final int contentHeight = parent.getMeasuredHeight() -
parent.getPaddingTop() - parent.getPaddingBottom();
offset = (contentHeight - (bottom - top)) / 2;
child.layout(left + leftDecorationWidth + lp.leftMargin,
top + topDecorationHeight + lp.topMargin + offset,
right - rightDecorationWidth - lp.rightMargin,
bottom - bottomDecorationHeight - lp.bottomMargin + offset);
} else {
final int contentWidth = parent.getMeasuredWidth() -
parent.getPaddingLeft() - parent.getPaddingRight();
offset = (contentWidth - (right - left)) / 2;
child.layout(left + leftDecorationWidth + offset + lp.leftMargin,
top + topDecorationHeight + lp.topMargin,
right - rightDecorationWidth - lp.rightMargin + offset,
bottom - bottomDecorationHeight - lp.bottomMargin);
}
}