我正在尝试使用setScaleX找到我所缺少的内容。
final ImageView iv = (ImageView) findViewById(R.id.imageView);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Start at 60
Log.d("test", "Before"+String.valueOf(iv.getWidth()));
iv.setScaleX((float) .5);
// Still at 60 after scale
Log.d("test", "After"+String.valueOf(iv.getWidth()));
}
});
我认为宽度会变成30.如何在缩放后获得宽度值?
答案 0 :(得分:5)
你可以乘以scale x or y
final ImageView iv = (ImageView) findViewById(R.id.imageView);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Start at 60
Log.d("test", "Before"+String.valueOf(iv.getWidth()* iv.getScaleX()));
iv.setScaleX((float) .5);
// Still at 60 after scale
Log.d("test", "After"+String.valueOf(iv.getWidth()* iv.getScaleX()));
}
});
答案 1 :(得分:0)
getWidth()
返回宽度,然后转换应用于视图(setScaleX
等等)。所以这是预期的。 getDrawingRect:
These bounds do not account for any transformation properties currently set on the view,
such as setScaleX(float) or setRotation(float).