2011-09-06 36 views
1

我有一個framelayout,其中有surfaceView和ImageView,ImageView是不可見的。基於某些事件,ImageView必須變得可見。但它並沒有到達前臺。我知道圖像已經變得可見了,因爲我可以在日誌中看到它,但它沒有顯示,因爲它不在頂部,SurfaceView。那麼我怎樣才能把ImageView帶到最頂端?這是我的代碼。在framelayout中將imageView帶到頂部

公共無效的onClick(視圖v){

if(v.getId() == R.id.Button1) { 

     Toast.makeText(getApplicationContext(), "Button1", Toast.LENGTH_SHORT).show(); 

     image = (ImageView) findViewById(R.id.lockIcon1); 

     if(!icon1show) { 
      icon1show = true; 
      image.setVisibility(View.VISIBLE); 
     }else { 
      icon1show = false; 
      image.setVisibility(View.INVISIBLE); 
     } 

    }else if(v.getId() == R.id.Button2) { 

     Toast.makeText(getApplicationContext(), "Button2", Toast.LENGTH_SHORT).show(); 

     image = (ImageView) findViewById(R.id.lockIcon2); 

     if(!icon2show) { 
      icon2show = true; 
      image.setVisibility(View.VISIBLE); 

     }else { 
      icon2show = false; 
      image.setVisibility(View.INVISIBLE); 

     } 

    } 
} 

XML代碼:

  <ImageView android:id="@+id/lockIcon2" 
         android:src="@drawable/lockicon" 
         android:visibility = "invisible" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"/> 
      <SurfaceView android:id="@+id/far_end" 
         android:layout_height="217.33dip" android:layout_width="291dip"/> 



    </FrameLayout> 

現在從 「lockIcon2」 的圖像沒有顯示是有SurfaceView連同在frameLayout中的imageView。所以請幫助!

+0

你需要SurfaceView與ImageView的可見??? – Jovan

+0

是的,我需要imageview在SurfaceView頂部可見 –

+0

好吧,我知道了!!在SurfaceView上放置一個surfaceView.setBackGroundColor(Color.TRANSPERANT),它允許顯示ImageView,dat很奇怪! –

回答

2

請添加一段代碼,以便我們爲您提供幫助。你使用bringToFront()方法嗎?

+0

嗨,我添加了您請求的代碼。我嘗試使用bringToFront()方法,但沒有用! –

+0

這似乎沒有回答這個問題 – JaviCasa

0

我完全不理解你,但我認爲你需要將你的SurfaceView消失,而不是隱形。當看不見它會佔據屏幕上的位置。試試這個...

相關問題