代码之家  ›  专栏  ›  技术社区  ›  Folkert van Heusden

ImageView对象始终为空

  •  0
  • Folkert van Heusden  · 技术社区  · 14 年前

    我有一个非常简单的Android活动布局,如下所示:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <ImageView id="@+id/blaimg"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
    

    现在,当我从 onOptionsItemSelected :

    ImageView imgView = (ImageView)findViewById(R.id.blaimg);
    

    内容 imgView 总是空的! 我做错什么了?

    谢谢!

    1 回复  |  直到 9 年前
        1
  •  0
  •   Jorgesys    14 年前

    将ImageView声明更改为:

    <ImageView android:id="@+id/blaimg"     
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>