1

ImageView の src としてデフォルトの画像を設定しています。次に、このイメージを変更したいと思います。私はこれをします:

ImageView imageView;
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.dude);

その結果、古いものの上に自分自身を配置するだけです。なぜでしょうか?

編集: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>
4

1 に答える 1

0

ImageView高さ/幅をWRAP_CONTENT に変更android:background="@drawable/car"し、ImageButton の背景から削除します。

<ImageView
    android:id="@+id/imageView"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center_horizontal"

    android:src="@drawable/car" />
于 2012-12-16T16:15:54.003 に答える