imageView.getLeft(),imageView.getLeft()结果0阵列使用 [英] imageView.getLeft(), imageView.getLeft() result 0 use array

查看:211
本文介绍了imageView.getLeft(),imageView.getLeft()结果0阵列使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么是错我的ImageView我声明与数组后,结果0

i dont know whats wrong with my imageView after i declaration with array, result 0

        imageViewTarget = new ImageView[] {
            (ImageView) findViewById(R.id.imageViewTarget1),
            (ImageView) findViewById(R.id.imageViewTarget2),
            (ImageView) findViewById(R.id.imageViewTarget3),
            (ImageView) findViewById(R.id.imageViewTarget4),
            (ImageView) findViewById(R.id.imageViewTarget5),
            (ImageView) findViewById(R.id.imageViewTarget6),
            (ImageView) findViewById(R.id.imageViewTarget7),
            (ImageView) findViewById(R.id.imageViewTarget8) };

    for (int i = 0; i < imageViewTarget.length; i++) {

        System.out.println("Left : "
                + imageViewTarget[i].getLeft() + " Right : "
                + imageViewTarget[i].getRight());
    }

任何想法?

推荐答案

您现在刚刚创建的视图,以便查看默认值设置为ZERO..after查看贴在窗口,你会得到正确的值..尝试得到这样的值 onWindowFocusChanged()方法..

You are just now created the view so the View default values are set to be ZERO..after View attached to the window You will get the correct values..try get the values like this in onWindowFocusChanged() method..

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    Button button = (Button) findViewById(R.id.button2);
    System.out.println(button.getLeft());
    System.out.println(button.getRight());
}

这篇关于imageView.getLeft(),imageView.getLeft()结果0阵列使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆