Android 文本视图的高度和宽度没有改变?
我在绝对布局上动态添加文本视图。下面是Absolute布局的代码。它起作用了。但问题是当我增加文本视图的文本大小时。然后文本视图的宽度和高度不变。有人请帮忙Android 文本视图的高度和宽度没有改变?,android,typeface,Android,Typeface,我在绝对布局上动态添加文本视图。下面是Absolute布局的代码。它起作用了。但问题是当我增加文本视图的文本大小时。然后文本视图的宽度和高度不变。有人请帮忙 @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); int maxHeight = 0; int maxWidth = 0; // Fi
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int count = getChildCount();
int maxHeight = 0;
int maxWidth = 0;
// Find out how big everyone wants to be
measureChildren(widthMeasureSpec, heightMeasureSpec);
// Find rightmost and bottom-most child
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
int childRight;
int childBottom;
LayoutParams lp
= (LayoutParams) child.getLayoutParams();
childRight = lp.x + child.getWidth();
childBottom = lp.y + child.getHeight();
maxWidth = Math.max(maxWidth, childRight);
maxHeight = Math.max(maxHeight, childBottom);
}
}
// Account for padding too
maxWidth += getPaddingLeft () + getPaddingRight ();
maxHeight += getPaddingTop () + getPaddingBottom ();
/* original
maxWidth += mPaddingLeft + mPaddingRight;
maxHeight += mPaddingTop + mPaddingBottom;
*/
// Check against minimum height and width
maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
resolveSize(maxHeight, heightMeasureSpec));
}
@覆盖
测量时的保护空隙(内部宽度测量等级、内部高度测量等级){
int count=getChildCount();
int maxHeight=0;
int maxWidth=0;
//了解每个人都想成为多大的人
测量儿童(宽度测量,高度测量);
//查找最右边和最下面的子级
for(int i=0;i
您只需在布局(.xml)处调整即可
您可以将其设置为“100dp”等。您不能使用
getWidth
和getHeight
,您应该在测量孩子后使用getMeasuredWidth
和getMeasuredHeight
,只需检查这是getMeasuredWidth和Height。它不起作用。所以这不是一个问题
android:layout_width="wrap_content"
android:layout_height="wrap_content"