0

android ImageView is not bringing to front in RelativeLayout

Tried to call bringtofront() didn't work tried setting visibility to true didn't work

XML CODE

           <?xml version="1.0" encoding="utf-8"?>
        <!-- This file is /res/layout/main.xml -->
         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/spellingLevel1Layout"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="horizontal" >

<RelativeLayout
    android:id="@+id/canvas_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/magnetboard" >

       <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="480dp"
            android:layout_marginTop="600dp"
            android:adjustViewBounds="true" />

     </RelativeLayout>

   </LinearLayout>

Java Code

   public class spellingLevel1 extends Activity {         
   rel1 = (RelativeLayout) findViewById(R.id.canvas_container);
   mImageView1 = (ImageView) findViewById(R.id.imageView1);
   image1();

}
  public void randomNumber() {
      Random rando = new Random();
      currentLetter = myImageList[rando.nextInt(myImageList.length)];
  }
  public void image1(){
      //randomNumber();

      mImageView1 = (ImageView) findViewById(R.id.imageView1);
      mImageView1.setBackgroundResource(R.drawable.spelling_);        
      mImageView1.bringToFront();
      mImageView1.requestLayout();




  }

UPDATED CODE

   rel1 = (RelativeLayout) findViewById(R.id.canvas_container);
   mImageView1 = (ImageView) findViewById(R.id.imageView1);
   image1();

}
  public void randomNumber() {
      Random rando = new Random();
      currentLetter = myImageList[rando.nextInt(myImageList.length)];
  }
  public void image1(){
      //randomNumber();

      mImageView1 = (ImageView) findViewById(R.id.imageView1);
      mImageView1.setImageResource(R.drawable.spelling_); //updated here to setImageResource          
      mImageView1.bringToFront();

Still does not show

its not the full code but it should be everything to help you see what is included in here

baron dune
  • 387
  • 1
  • 5
  • 23

1 Answers1

1

You should define the image source of the ImageView. because it's size is set to wrap_content and it has no content, the size stays 0.

Rotem
  • 1,472
  • 2
  • 11
  • 18
  • 1
    This seems a little misleading. The width attribute stays at `wrap_content` - so once content is added (aka the image source), the width will no longer be zero. Lookup `LayoutParams` for a better understanding. – Phil Apr 30 '13 at 15:23
  • That's right, but he never set the content so it stays on 0 :). – Rotem Apr 30 '13 at 15:36
  • He should change the setBackgroundImage to setImageResource – Rotem Apr 30 '13 at 15:38
  • I have an array of images that's why it's set background image. How would I convert the image resource to accept an array form – baron dune Apr 30 '13 at 17:00
  • the same way you do this now, just change the setBackgroundImage to setImageResource. I'm not sure I understand the problem – Rotem Apr 30 '13 at 17:05
  • I think I may be confused because I am a novice. Basically when I try calling imageresource it gives me an error – baron dune Apr 30 '13 at 22:27
  • now what happens is the imageview is not bringing to the front of the drawable relative background – baron dune May 02 '13 at 13:02