[英]Changing imageview is drawing ontop on old image
I have a default image set as a src for an ImageView. 我有一个默认图像设置为ImageView的src。 Then i want to change this image.
然后,我想更改此图像。 I do this:
我这样做:
ImageView imageView;
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.dude);
The result is that it only puts itself ontop of the old one, why could that be? 结果是它只能放在旧的之上,为什么会这样呢?
EDIT: added the xml-file: 编辑:添加了xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageView"
android:layout_width="241dp"
android:layout_height="214dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/car"
android:src="@drawable/car" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button0"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="clickclick"
android:textSize="30sp" />
<Button
android:id="@+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="@+id/textViewGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/instructionsGame"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Change ImageView
height/width to WRAP_CONTEN
T and remove android:background="@drawable/car"
from ImageButton background : 将
ImageView
高度/宽度更改为WRAP_CONTEN
T并从ImageButton背景中删除android:background="@drawable/car"
:
<ImageView
android:id="@+id/imageView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/car" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.