问题描述
谁能告诉我如何解决以下跟踪:
W /浏览(16810):requestLayout()不正确地调用
theme.effects.TopCenterImageView {41dc73f0 V.ED .... ........
0,0-480,690#7f060066应用:ID / normal_image}在第二
布局传递:张贴在下一帧
下面是$ C $下TopCenterImageView:
公共类TopCenterImageView扩展ImageView的{
公共TopCenterImageView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
超(背景下,ATTRS,defStyle);
setScaleType(ScaleType.MATRIX);
}
公共TopCenterImageView(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
setScaleType(ScaleType.MATRIX);
}
公共TopCenterImageView(上下文的背景下){
超(上下文);
setScaleType(ScaleType.MATRIX);
}
@覆盖
保护布尔的setFrame(INT L,INT T,INT R,int b)在{
如果(getDrawable()== NULL){
返回super.setFrame(L,T,R,B);
}
字模= getImageMatrix();
浮动比例因子=的getWidth()/(浮点)getDrawable()getIntrinsicWidth()。
matrix.setScale(比例因子,比例因子,0,0);
setImageMatrix(矩阵);
返回super.setFrame(L,T,R,B);
}
}
可以看出<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/1.5_r4/android/widget/ImageView.java#ImageView.setScaleType%28android.widget.ImageView.ScaleType%29">here, setScaleType会调用requestLayout,但ImageView的的构造函数之前已经调用它。这样就会造成布局具有称为多requestLayout,一个布局传递期间。这只是一个警告,因为在一个小规模的,这不是一个问题。
您会发现一些好的研究this螺纹(不是roboguice部分虽然)。
Can anyone tell me how to fix the following trace:
W/View (16810): requestLayout() improperly called by
theme.effects.TopCenterImageView{41dc73f0 V.ED.... ........
0,0-480,690 #7f060066 app:id/normal_image} during second
layout pass: posting in next frame
Here is the code for TopCenterImageView:
public class TopCenterImageView extends ImageView {
public TopCenterImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setScaleType(ScaleType.MATRIX);
}
public TopCenterImageView(Context context, AttributeSet attrs) {
super(context, attrs);
setScaleType(ScaleType.MATRIX);
}
public TopCenterImageView(Context context) {
super(context);
setScaleType(ScaleType.MATRIX);
}
@Override
protected boolean setFrame(int l, int t, int r, int b) {
if (getDrawable() == null) {
return super.setFrame(l, t, r, b);
}
Matrix matrix = getImageMatrix();
float scaleFactor = getWidth() / (float) getDrawable().getIntrinsicWidth();
matrix.setScale(scaleFactor, scaleFactor, 0, 0);
setImageMatrix(matrix);
return super.setFrame(l, t, r, b);
}
}
As seen here, setScaleType will call requestLayout, but the constructor of ImageView already call it before. So it will cause the layout to have multiple requestLayout called, one during the layout pass. It's just a warning because at a small scale, it's not a problem.
You will find some good research in this thread (not the roboguice part though).
这篇关于追踪:requestLayout()不当叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!