0

android ImageView 没有在 RelativeLayout 中出现

尝试调用 bringtofront() 无效尝试将可见性设置为 true 无效

XML 代码

           <?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 代码

   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();




  }

更新代码

   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();

还是不显示

它不是完整的代码,但它应该可以帮助您查看此处包含的内容

4

1 回答 1

1

您应该定义ImageView. 因为它的大小设置为wrap_content并且没有内容,所以大小保持为 0。

于 2013-04-30T14:55:56.533 回答