[英]ImageView doesn't show up
实际上,我想在不同位置创建相同图片的数组。 好吧,它可以工作,但是不会显示图像。 意思是,它们是被创建的,但是不可见,我真的不知道为什么。
我尝试了不同的方法,只在显示屏上显示了一张图像,但根本无法正常工作。
<ImageView
android:id="@+id/tapfield"
android:src="@drawable/tapfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/mole"
android:src="@drawable/mole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
那就是XML文件。 显示痣图像工作正常。
假设我有以下代码,以包含其他图像
public class game extends Activity {
private ImageView pic;
private Mole mole;
private Display display;
private Fields fields;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.initialize();
}
public void initialize() {
setContentView(R.layout.activity_game);
// create mole
this.mole = new Mole();
this.mole.setPicture((ImageView) findViewById(R.id.mole));
this.mole.setY((int) this.mole.getPicture().getY());
this.mole.setTempo(10);
//test
pic = (ImageView) findViewById(R.id.tapfield);
}
}
public class Mole {
private ImageView picture;
private int y;
private int tempo;
// Getter und Setter
public void setPicture(ImageView picture){
this.picture = picture;
}
public ImageView getPicture() {
return picture;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getTempo() {
return tempo;
}
public void setTempo(int tempo) {
this.tempo = tempo;
}
}
对于Mo鼠,它的工作原理非常好。 对于Tapfield,它不起作用。 不过,我将ID更改为* .mole或其他名称。
除了将系统图像和背景色设置为黑色之外,我使用了您的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000">
<ImageView
android:id="@+id/tapfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_dialog_email"/>
<ImageView
android:id="@+id/mole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@android:drawable/ic_dialog_dialer"/>
</RelativeLayout>
结果:
我希望这将帮助您在获得工作版本时了解问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.