本文整理汇总了Java中android.view.View.getLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java View.getLayoutParams方法的具体用法?Java View.getLayoutParams怎么用?Java View.getLayoutParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.getLayoutParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: offsetY
import android.view.View; //导入方法依赖的package包/类
protected int offsetY(View child, boolean centreInVisibleBounds, boolean marginInclude) {
int current;
MarginLayoutParams marginLp = (marginInclude && child.getLayoutParams() instanceof MarginLayoutParams) ? (MarginLayoutParams) child.getLayoutParams() : null;
if (centreInVisibleBounds) {
current = (child.getTop() + child.getBottom()) >> 1;
if (marginLp != null) {
current = current + (marginLp.bottomMargin - marginLp.topMargin) / 2;
}
return current - mVisibleBounds.centerY() + mVisibleBounds.top - getPaddingTop();
} else {
current = child.getTop();
if (marginLp != null) {
current = current - marginLp.topMargin;
}
return current - getPaddingTop();
}
}
示例2: measureView
import android.view.View; //导入方法依赖的package包/类
public static void measureView(View child) {
ViewGroup.LayoutParams p = child.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(-1, -2);
}
int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
int lpHeight = p.height;
int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, 1073741824);
} else {
childHeightSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
}
child.measure(childWidthSpec, childHeightSpec);
}
示例3: measureScrapChild
import android.view.View; //导入方法依赖的package包/类
private void measureScrapChild(View child, int position, int widthMeasureSpec) {
LayoutParams p = (LayoutParams) child.getLayoutParams();
if (p == null) {
p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 0);
child.setLayoutParams(p);
}
p.viewType = mAdapter.getItemViewType(position);
p.forceAdd = true;
int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec,
mListPadding.left + mListPadding.right, p.width);
int lpHeight = p.height;
int childHeightSpec;
if (lpHeight > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
child.measure(childWidthSpec, childHeightSpec);
}
示例4: nextViewFromScrapList
import android.view.View; //导入方法依赖的package包/类
/**
* Returns the next item from the scrap list.
* <p>
* Upon finding a valid VH, sets current item position to VH.itemPosition + mItemDirection
*
* @return View if an item in the current position or direction exists if not null.
*/
private View nextViewFromScrapList() {
final int size = mScrapList.size();
for (int i = 0; i < size; i++) {
final View view = mScrapList.get(i).itemView;
final LayoutParams lp = (LayoutParams) view.getLayoutParams();
if (lp.isItemRemoved()) {
continue;
}
if (mCurrentPosition == lp.getViewLayoutPosition()) {
assignPositionFromScrapList(view);
return view;
}
}
return null;
}
示例5: drawVertical
import android.view.View; //导入方法依赖的package包/类
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例6: onLayout
import android.view.View; //导入方法依赖的package包/类
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int count = getChildCount();
int parentLeft = getPaddingLeft();
int parentRight = (right - left) - getPaddingRight();
int parentTop = getPaddingTop();
int parentBottom = (bottom - top) - getPaddingBottom();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != 8) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int childLeft = parentLeft + lp.leftMargin;
int childTop = parentTop + lp.topMargin;
child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight());
}
}
}
示例7: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
mWidth = getMeasuredWidth();
mHeight = getMeasuredHeight();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int childLeft = mPaddingLeft + lp.x;
if (lp.width > 0)
childLeft += (int) ((mWidth - lp.width) / 2.0);
else
childLeft += (int) ((mWidth - child.getMeasuredWidth()) / 2.0);
int childTop = mPaddingTop + lp.y;
if (lp.height > 0)
childTop += (int) ((mHeight - lp.height) / 2.0);
else
childTop += (int) ((mHeight - child.getMeasuredHeight()) / 2.0);
child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight());
}
}
}
示例8: getMarginStart
import android.view.View; //导入方法依赖的package包/类
static int getMarginStart(View v) {
if (v == null) {
return 0;
}
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
return MarginLayoutParamsCompat.getMarginStart(lp);
}
示例9: drawHorizontal
import android.view.View; //导入方法依赖的package包/类
public void drawHorizontal(Canvas c, RecyclerView parent) {
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getLeft() - params.leftMargin;
final int right = child.getRight() + params.rightMargin
+ mDivider.getIntrinsicWidth();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例10: drawVerticalDivider
import android.view.View; //导入方法依赖的package包/类
private void drawVerticalDivider(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例11: expand
import android.view.View; //导入方法依赖的package包/类
/**
* Expand a hidden view
* @param v - current view
*/
private static void expand(final View v) {
v.measure(CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
Animation anim = new Animation() {
/**
* Transform a view
* @param interpolatedTime - time to transition
* @param t - transition to apply
*/
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? CoordinatorLayout.LayoutParams.WRAP_CONTENT
: (int)(targetHeight * interpolatedTime);
v.requestLayout();
}
/**
* Returns if the bounds will change
* @return Returns true
*/
@Override
public boolean willChangeBounds() {
return true;
}
};
// 3dp/ms
anim.setDuration(((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)) * 3);
v.startAnimation(anim);
}
示例12: setViewMargin
import android.view.View; //导入方法依赖的package包/类
public ViewGroup.MarginLayoutParams setViewMargin(View view, int left, int top, int right, int bottom) {
if (view == null) {
return null;
}
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
if (lp != null) {
lp.setMargins(left, top, right, bottom);
view.setLayoutParams(lp);
}
return lp;
}
示例13: isDrawerOpen
import android.view.View; //导入方法依赖的package包/类
public boolean isDrawerOpen(View drawer) {
if (!isDrawerView(drawer)) {
throw new IllegalArgumentException("View " + drawer + " is not a drawer");
} else if ((((LayoutParams) drawer.getLayoutParams()).openState & 1) == 1) {
return true;
} else {
return false;
}
}
示例14: onDrawOver
import android.view.View; //导入方法依赖的package包/类
/**
* @param c
* @param parent
* @param state
*/
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (dividerDrawable == null) {
return;
}
int childCount = parent.getChildCount();
int rightV = parent.getWidth();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int leftV = parent.getPaddingLeft() + child.getPaddingLeft();
int bottomV = child.getTop() - params.topMargin;
int topV = bottomV - dividerDrawable.getIntrinsicHeight();
int topH = child.getTop() + params.topMargin;
int bottomH = child.getBottom() + params.bottomMargin;
int rightH = child.getLeft() - params.leftMargin;
int leftH = rightH - dividerDrawable.getIntrinsicWidth();
dividerDrawable.setBounds(leftH, topH, rightH, bottomH);
dividerDrawable.draw(c);
dividerDrawable.setBounds(leftV, topV, rightV, bottomV);
dividerDrawable.draw(c);
}
}
示例15: addMarginTopToContentChild
import android.view.View; //导入方法依赖的package包/类
/**
* add marginTop to simulate set FitsSystemWindow true
*/
private static void addMarginTopToContentChild(View mContentChild, int statusBarHeight) {
if (mContentChild == null) {
return;
}
if (!TAG_MARGIN_ADDED.equals(mContentChild.getTag())) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mContentChild.getLayoutParams();
lp.topMargin += statusBarHeight;
mContentChild.setLayoutParams(lp);
mContentChild.setTag(TAG_MARGIN_ADDED);
}
}