简体   繁体   English

android,ImageView屏幕底部

[英]android, ImageView bottom of screen

Trying to put a ImageView on the bottom of the screen, + a fit width. 尝试将ImageView放在屏幕底部,再加上合适的宽度。

Fit width are ok, but image are near half its height too lower. 适合的宽度还可以,但是图像的高度近一半过低。

A guess: Are the Y of a Imageview centerBased? 一个猜测:Imageview的Y是否基于center?

Please don't profite "layout" solution, I look for a X, y, height, width solution. 请不要使用“布局”解决方案,我正在寻找X,y,高度,宽度的解决方案。 :) :)

(so simple in iOS ) (在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());

}

Why don't you set it like this: 为什么不这样设置:

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)imageV.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

imageV.setLayoutParams(params); 

@Udi Idan was right, but if you still want to use X, Y, width, height solution then maybe you can try this @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: I tried some codes like your sample and get the wrong result, maybe we need to calculate ActionBar's height. P / S:我尝试了像您的示例这样的代码,但得到了错误的结果,也许我们需要计算ActionBar的高度。 You could try. 你可以试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM