我有一个ImageView的,不具有酶活性的布局:我可以在课堂上设置布局吗? (无活性)
pieza.xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:src="@drawable/arribin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
和在另一方面,我有一个类,其中我尝试修改布局膨胀:
public void init(){
res = this.getContext().getApplicationContext().getResources();
lInf = (LayoutInflater)(getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
lInf.inflate(R.layout.game, this, true);
}
private int getPieceId(){
//trying to set the image
ImageView image=(ImageView)findViewById(R.id.image);
image.setImageResource(R.drawable.fast);
return R.layout.pieza;
}
...
View newPiece = lInf.inflate(getPieceId(), null);
而且logcat的:
ImageView.setImageResource(INT)”上空对象引用
我可以在没有Activity的情况下设置布局的ImageView吗?
我认为这些不是问题(只是试过了,它不起作用)。 R.layout.game是活动的布局,并且工作正常。我认为问题是pieza.xml没有活动。无论如何谢谢 –
检查我编辑的答案。 – Antrromet
logcat返回相同的:( –