ImageView不显示
问题描述:
其实,我想在不同的位置创建一个相同图片的数组。那么,它的工作原理,但不显示图像。手段,他们被创造,但不可见,我真的不知道为什么。ImageView不显示
我尝试了不同的事情,只在显示屏上显示一个图像,但根本不起作用。
<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;
}
}
鼹鼠它完美的罚款。 对于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>
和结果:
我希望这将有助于你知道哪里是你的问题当你得到一个工作版本....
'它不工作'意味着应用程序崩溃?或者只是不显示ImageView?如果这是一个LogCat错误只是将其粘贴在您的问题上,那么我们可以帮助您 –
尝试使用您的ID名称和可绘制的名称不同 –
您使用哪种布局作为父级? –