我有一個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返回相同的:( –