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 に答える