我有一个ImageView,我希望它在应用程序启动后放大
所以,首先我这样做了:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.mainLayout);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.screenshot198);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(params);
layout.addView(imageView);
imageView.setPivotX(1.0f);
imageView.setScaleX(1.5f);
imageView.setScaleY(1.5f);
}
效果很好!
然后我尝试通过调整代码将其设置在底部:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.mainLayout);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.screenshot198);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
imageView.setLayoutParams(params);
layout.addView(imageView);
imageView.setPivotX(1.0f);
imageView.setPivotY(1.0f);
imageView.setScaleX(1.5f);
imageView.setScaleY(1.5f);
}
喂!我的树发生了什么事?
这两段代码之间的唯一区别是,我添加了[params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);]以便将图像放在底部,并添加了[setPivotY(1.0f);]所以图像应从底部向上扩展。
但似乎[setPivotY(1.0f);]无法正常工作。我缺少什么?谢谢!
答案 0 :(得分:0)
@rupps的评论令我惊讶。更改为setPivotY(view.getHeight())
修复我的案例。
使用setPivotY(view.getBottom())
时,我在使用setScaleY()
时获得了意外的偏移/保证金。