ImageView doesn't show up

2.1k views Asked by At

Actually, i want to create an array of the same picture in different positions. Well, it works, but the image isn't displayed. Means, they are created, but not visible and i seriously don't know why.

I tried different things to get just a single image on the display, but doesn't work at all.

<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" />

That's the XML-file. Displaying the mole image works fine.

Let's say i have the following code, to include the other image

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;
        }
    }

For Mole it works perfectly fine. For Tapfield it doesn't work. Nevertheless i change the id to the *.mole or something other.

1

There are 1 answers

0
Maher Abuthraa On

I used your code except that I set system images and background color black:

<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>

and result:

enter image description here

I hope that will help you to know where is your problem when you get a working version ....