我试图设置一个imageview的资源如下:
代码:
ImageView imageView = new ImageView(getApplicationContext());
imageView.setImageResource(R.drawable.bg);但我在屏幕上什么也没看到。
我可以
imageView = (ImageView) findViewById(R.id.bgView);它可以工作,但在我的例子中,我不能使用它,因为我需要将图像视图应用到图像视图的数组中。
还有其他方法来构造我的图像视图吗?还是我做错了什么?
编辑:
我的xml看起来像:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/entire_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context="com.example.guilyan.Game" >
<ImageView
android:id="@+id/bgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/Descript"
android:scaleType="fitXY"
android:src="@+drawable/testpicks" />
</FrameLayout>发布于 2014-06-05 04:17:31
我认为如果布局id为layout.just,则应该将动态创建的图像视图添加到您的this.Suppose中。
frameLayout.addView(imageView);发布于 2014-06-05 04:06:30
使用
new ImageView(getApplicationContext());不正确。您需要使用活动上下文,而不是应用程序。当然,在初始化视图之后,您需要将其附加到父级。
https://stackoverflow.com/questions/24051415
复制相似问题