本文整理汇总了Java中android.view.ViewGroup.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java ViewGroup.getWidth方法的具体用法?Java ViewGroup.getWidth怎么用?Java ViewGroup.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.ViewGroup
的用法示例。
在下文中一共展示了ViewGroup.getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 将标签放置于对应RelativeLayout的对应位置,考虑引入postion作为参数??
*
* @param parent
* @param left
* @param top
*/
public void draw(ViewGroup parent, final int left, final int top, boolean isLeft) {
this.parentWidth = parent.getWidth();
if (parentWidth <= 0) {
parentWidth = ScreenUtils.getScreenWidth();
}
setImageWidth((int) parentWidth);
this.parentHeight = parentWidth;
if (isLeft) {
labelTxtRight.setVisibility(View.VISIBLE);
labelTxtLeft.setVisibility(View.GONE);
setupLocation(left, top);
parent.addView(this);
} else {
labelTxtRight.setVisibility(View.GONE);
labelTxtLeft.setVisibility(View.VISIBLE);
setupLocation(left, top);
parent.addView(this);
}
}
示例2: getDistancePoint
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public PointF getDistancePoint(ViewGroup parent, List<View> children) {
PointF point = super.getDistancePoint(parent, children);
switch (direction) {
case TOP_TO_BOTTOM:
return new PointF(parent.getWidth() / 2.0F, 0F);
case BOTTOM_TO_TOP:
return new PointF(parent.getWidth() / 2.0F, parent.getHeight());
case LEFT_TO_RIGHT:
return new PointF(0F, parent.getHeight() / 2.0F);
case RIGHT_TO_LEFT:
return new PointF(parent.getWidth(), parent.getHeight() / 2.0F);
default:
throw new AssertionError("Must be a valid Direction argument type");
}
}
示例3: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public void prepare(View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - target.getLeft();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "translationX", distance, 0)
);
}
示例4: addTo
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 将标签放置于对应RelativeLayout的对应位置,考虑引入postion作为参数??
*
* @param parent
* @param left
* @param top
*/
public void addTo(ViewGroup parent, final int left, final int top) {
if (left > parent.getWidth() / 2) {
tagInfo.setLeft(false);
}
this.parentWidth = parent.getWidth();
if (parentWidth <= 0) {
parentWidth = ScreenUtils.getScreenWidth();
}
setImageWidth((int) parentWidth);
this.parentHeight = parentWidth;
if (emptyItem) {
labelTxtRight.setVisibility(View.GONE);
labelTxtLeft.setVisibility(View.GONE);
setupLocation(left, top);
parent.addView(this);
} else if (tagInfo.isLeft()) {
labelTxtRight.setVisibility(View.VISIBLE);
labelTxtLeft.setVisibility(View.GONE);
setupLocation(left, top);
parent.addView(this);
} else {
labelTxtRight.setVisibility(View.GONE);
labelTxtLeft.setVisibility(View.INVISIBLE);
setupLocation(20, 20);
parent.addView(this);
post(new Runnable() {
@Override
public void run() {
int toLeft = left - getWidth() + labelIcon.getWidth();
setupLocation(toLeft, top);
labelTxtLeft.setVisibility(View.VISIBLE);
}
});
}
}
示例5: setVideoLayout
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* Set the display options
*
* @param layout <ul>
* <li>{@link #VIDEO_LAYOUT_ORIGIN}
* <li>{@link #VIDEO_LAYOUT_SCALE}
* <li>{@link #VIDEO_LAYOUT_STRETCH}
* <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
* <li>{@link #VIDEO_LAYOUT_ZOOM}
* </ul>
* @param aspectRatio video aspect ratio, will audo detect if 0.
*/
public void setVideoLayout(int layout, float aspectRatio) {
LayoutParams lp = getLayoutParams();
Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
float windowRatio = windowWidth / (float) windowHeight;
float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
mSurfaceHeight = mVideoHeight;
mSurfaceWidth = mVideoWidth;
if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
lp.width = (int) (mSurfaceHeight * videoRatio);
lp.height = mSurfaceHeight;
} else if (layout == VIDEO_LAYOUT_ZOOM) {
lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
} else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
ViewGroup parent = (ViewGroup) getParent();
float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
} else {
boolean full = layout == VIDEO_LAYOUT_STRETCH;
lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
}
setLayoutParams(lp);
getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
mVideoLayout = layout;
mAspectRatio = aspectRatio;
}
示例6: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
protected void prepare(AnimatorSet animatorSet, View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - target.getLeft();
animatorSet.playTogether(
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "translationX", distance, 0)
);
}
示例7: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
protected void prepare(AnimatorSet animatorSet, View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - target.getLeft();
animatorSet.playTogether(
ObjectAnimator.ofFloat(target, "alpha", 1, 0),
ObjectAnimator.ofFloat(target, "translationX", 0, distance)
);
}
示例8: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
protected void prepare(AnimatorSet animatorSet, View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - target.getLeft();
animatorSet.playTogether(
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "translationX", -distance, 0)
);
}
示例9: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
protected void prepare(View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - parent.getLeft();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0),
ObjectAnimator.ofFloat(target, "scaleX", 1, 0.475f, 0.1f),
ObjectAnimator.ofFloat(target, "scaleY", 1, 0.475f, 0.1f),
ObjectAnimator.ofFloat(target, "translationX", 0, -42, distance)
);
}
示例10: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public void prepare(View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - target.getLeft();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "alpha", 0, 1),
ObjectAnimator.ofFloat(target, "translationX", -distance, 0)
);
}
示例11: prepare
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public void prepare(View target) {
ViewGroup parent = (ViewGroup) target.getParent();
int distance = parent.getWidth() - target.getLeft();
getAnimatorAgent().playTogether(
ObjectAnimator.ofFloat(target, "alpha", 1, 0),
ObjectAnimator.ofFloat(target, "translationX", 0, distance)
);
}
示例12: onCreateViewHolder
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public BaseWrappedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
BaseWrappedViewHolder baseWrappedViewHolder = super.onCreateViewHolder(parent, viewType);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) baseWrappedViewHolder.itemView.getLayoutParams();
layoutParams.width = (parent.getWidth() - 2 * (PixelUtil.dp2px(mPagePadding + showCardWidth)));
baseWrappedViewHolder.itemView.setLayoutParams(layoutParams);
baseWrappedViewHolder.itemView.setPadding(PixelUtil.dp2px(mPagePadding), 0, PixelUtil.dp2px(mPagePadding), 0);
return baseWrappedViewHolder;
}
示例13: AdjustHorizontalCenteredOutOfBounds
import android.view.ViewGroup; //导入方法依赖的package包/类
private static void AdjustHorizontalCenteredOutOfBounds(View instaBadgeView, ViewGroup rootView, Point point, Coordinates rootCoordinates) {
ViewGroup.LayoutParams params = instaBadgeView.getLayoutParams();
int rootWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();
if (instaBadgeView.getMeasuredWidth() > rootWidth) {
point.x = rootCoordinates.left + rootView.getPaddingLeft();
params.width = rootWidth;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
instaBadgeView.setLayoutParams(params);
measureViewWithFixedWidth(instaBadgeView, rootWidth);
}
}
示例14: measureNumColumns
import android.view.ViewGroup; //导入方法依赖的package包/类
private int measureNumColumns(ViewGroup layout, CharSequence item, CharSequence title) {
int colWidth = 0;
int viewWidth = 0;
if (getSize() > 0) {
// Use the first item to measure the column width
TextView tempView = createTextView(item);
tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tempView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
colWidth = tempView.getMeasuredWidth() + 4;
// Stack overflow when called just after resized layout !?
viewWidth = layout.getWidth();
// If table layout not inflated yet, use device width
if (viewWidth <= 0) {
viewWidth = mRes.getDisplayMetrics().widthPixels - 2 * mRes.getDimensionPixelOffset(R.dimen.activity_horizontal_margin);
}
if (title != null) {
tempView = createTextView(title);
tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tempView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
viewWidth -= tempView.getMeasuredWidth();
}
}
if (colWidth != 0) {
return Math.max(1, viewWidth/colWidth);
} else {
return 1;
}
}
示例15: updateCanvas
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* Draws the leds on the screen.
* @param screen
*/
private void updateCanvas(ViewGroup screen) {
double scaleX = (double) screen.getWidth() / getScreenWidth();
double scaleY = (double) screen.getHeight() / getScreenHeight();
double translateX = (double) getScreenWidth()*getCurrentScreen();
// TODO: calculate..
double translateY = 0;
ArrayList<Integer> colors = RemoteState.getInstance().getColors();
ArrayList<Rect> rects = RemoteState.getInstance().getLeds();
for(int i = 0; i < rects.size(); i++) {
TextView rect = new TextView(this);
rect.setText("" + (i+1));
rect.setGravity(Gravity.CENTER);
rect.setBackgroundColor(colors.get(i));
int width = (int) (rects.get(i).width() * scaleX);
int height = (int) (rects.get(i).height() *scaleY);
int left = (int) ((rects.get(i).left - translateX) * scaleX);
int top = (int) ((rects.get(i).top - translateY) * scaleY);
FrameLayout.LayoutParams llp = new FrameLayout.LayoutParams(width, height);
llp.setMargins(left, top , 0, 0);
rect.setLayoutParams(llp);
screen.addView(rect);
}
}