尝试将ImageView放在屏幕底部,+适合宽度。
适合的宽度没问题,但是图像的高度接近一半。
猜测:Imageview中心的Y是否基于?
请不要夸奖“布局”解决方案,我寻找X,Y,高度,宽度解决方案。 :)
(iOS中这么简单)
private void layout_imageBottom(ImageView imageV) {
imageV.setScaleType(ImageView.ScaleType.FIT_XY);
imageV.setX(0);
imageV.setMinimumHeight(imageV.getHeight());
imageV.setMaxHeight(imageV.getHeight());
Integer iS= Settings.getScreenSize(getApplicationContext()).x;
imageV.setMinimumWidth(Settings.getScreenSize(getApplicationContext()).x);
imageV.setMaxWidth(Settings.getScreenSize(getApplicationContext()).x);
imageV.setY(Settings.getScreenSize(getApplicationContext()).y - imageV.getHeight());
}
答案 0 :(得分:2)
为什么不这样设置:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)imageV.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
imageV.setLayoutParams(params);
答案 1 :(得分:0)
@Udi Idan是对的,但是如果你还想使用X,Y,宽度,高度解决方案那么也许你可以试试这个
int width = screenW;
int height = 80;
final ImageView imageView = new ImageView(this);
LayoutParams params = new LayoutParams(width, height);
imageView.setLayoutParams(params);
imageView.setBackgroundResource(R.drawable.ic_launcher);
layout.addView(imageView);
imageView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
imageView.setX(0);
imageView.setY(layout.getMeasuredHeight() - imageView.getMeasuredHeight()
- imageView.getPaddingBottom() - imageView.getPaddingTop());
}
});
P / S:我尝试了一些像你的样本一样的代码并得到错误的结果,也许我们需要计算ActionBar的高度。你可以试试。