2013-04-18 47 views
0

我是一個新手,並且一直在爲此工作幾天而沒有任何成功。有人的幫助將非常感激。設置2個ImageView中的一個透明/不可見,顯示白色屏幕

我有兩個ImageViews,一個在另一個後面的活動。我想做第一個(頂部的),不可見或透明的,所以我可以在我的代碼中使用它。第二個(底部的)應該保持可見,以便用戶可以與之交互。我試過這樣做,首先將畫布設置爲透明,然後是TOP ImageVIew,這會導致屏幕顯示白色,而不是在後面顯示ImageView(底部)。請有人解釋一下爲什麼會發生這種情況,並建議我有一個更好的方法來實現我的目的?提前致謝。

這裏是我的.java代碼:

public class MainActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     final ImageView imageView = (ImageView) findViewById(R.id.imageView1); 
     imageView.setVisibility(View.INVISIBLE); 

     imageView.setOnTouchListener(new ImageView.OnTouchListener(){ 
      public boolean onTouch(View v, MotionEvent event) { 
       if(event.getAction() == MotionEvent.ACTION_DOWN) { 
        Drawable imgDrawable = ((ImageView)imageView).getDrawable(); 
        Bitmap mutableBitmap = Bitmap.createBitmap(imageView.getWidth(), imageView.getHeight(), Bitmap.Config.ARGB_8888); 
        Canvas canvas = new Canvas(mutableBitmap); 
        imgDrawable.draw(canvas); 
        int pixel = mutableBitmap.getPixel((int)event.getX(), (int)event.getY()); 
        Log.i("PIXEL COLOR", ""+pixel); 

        int alpha = Color.alpha(pixel); 
        int red = Color.red(pixel); 
        int blue = Color.blue(pixel); 
        int green = Color.green(pixel); 
        String color = String.format("#%02X%02X%02X%02X", alpha, red, green, blue); 
        Log.i("RGB", color); 

        float[] hsv = new float[3]; 
        Color.RGBToHSV(red, green, blue, hsv); 
        Log.i("HSV_H", "Hue=" + hsv[0]); 
        Log.i("HSV_H", "Saturation=" + hsv[1]); 
        Log.i("HSV_H", "Value=" + hsv[2]); 
       } 
       return true; 
      } 
     }); 
} 

}

這裏是我的.xml代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/lapices" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/lapices" /> 

</LinearLayout> 

回答

0

我實在不明白你想達到的目標。 它應該存在一個更好的方法,但就我可以看到,如果您將您的LinearLayout在RelativeLayout中,並且您更改它應該工作的圖像視圖的順序。

順便說一下一些代碼。

<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" > 
<ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY" 
     android:visibility="invisible" 
     android:src="@drawable/ic_action_search" /> 


</RelativeLayout> 
+0

感謝您的回覆user2122876,非常感謝。我想要使​​用2個ImageView圖層,一個在另一個的頂部,並從頂部看不到的用戶交互,但我無法弄清楚如何在Android中執行此操作,因爲看起來不可見的ImageViews不接受用戶相互作用。或者有沒有辦法實現這一點?感謝你的寶貴時間。 – patriciasc

相關問題