我在android中有自定义视图。
@Component
@javax.jws.WebService (endpointInterface="com.test.IPSoap")
public class SOAPprocessImpl implements IPSoap {
private static final Logger logger = Logger.getLogger(SOAPprocessImpl.class.getName());
@Autowired //spring directly injects this object
private IValidator validator;
public IRResponse GetBalance(TSSearchParams SearchParams) {
// Some processing logic
}
}
我public class NumberTextView extends View {
}
override
的方法。
onMeasure
但是视图的位置是错误的。查看@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int newWidth;
int height = getMeasuredHeight();
float scale = getMeasuredHeight() / (float) mNumbers.get("t0").getHeight();
float ratio = 140 / 224f;
mNumberWidth = (int) Math.ceil(height * ratio);
mDotWidth = (int) Math.ceil(scale * mNumbers.get("dot").getWidth());
mDotheight = (int) Math.ceil(scale * mNumbers.get("dot").getHeight());
if (mNumber.contains(".")) {
newWidth = (mNumber.length() - 1) * mNumberWidth + mDotWidth;
} else {
newWidth = mNumber.length() * mNumberWidth;
}
setMeasuredDimension(newWidth, getMeasuredHeight());
Log.d(TAG, "onMeasure width " + getMeasuredWidth() + ", height " + getMeasuredHeight());
}
@Override
public void layout(@Px int l, @Px int t, @Px int r, @Px int b) {
super.layout(l, t, r, b);
Log.d(TAG, "layout " + l + ", " + t + ", " + r + ", " + b);
}
public void setNumber(String number) {
mNumber = number;
requestLayout();
}
和onMeasure
的日志。
layout
自定义视图用于D/NumberTextView: onMeasure width 2151, height 1146
D/NumberTextView: onMeasure width 630, height 336
D/NumberTextView: layout -535, 90, 1616, 426
D/NumberTextView: onMeasure width 2151, height 1146
D/NumberTextView: onMeasure width 630, height 336
D/NumberTextView: layout -535, 90, 1616, 426
。
RelativeLayout
查看<com.test.view.NumberTextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="112dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp">
</com.test.view.NumberTextView>
的日志。当视图高度从layout
更改为1146
时,视图的高度是正确的。但宽度没有变化。
336
336 == 426 - 90
630 != 1616-(-535)
是旧宽度1616-(-535)
。