Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting one of 2 ImageViews transparent/invisible, shows white screen
    primarykey
    data
    text
    <p>I am a newbie and have been working on this for a couple of days now without any success. Somebody's help would be very appreciated.</p> <p>I have two ImageViews, one behind the other in an Activity. I would like to make the first one (the one at the top), invisible or transparent, so I can use it internally in my code. The second one (the one on the bottom), should remain visible, so the user can interact with it. I tried doing it setting the canvas transparent first, and then the TOP ImageVIew, which causes the screen to show white color, instead of showing the ImageView behind (the BOTTOM one). Could somebody please, explain me why this is happening, and suggest me a better approach for achieving my purpose? Thanks in advance.</p> <p>Here is my .java code:</p> <pre><code>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; } }); } </code></pre> <p>}</p> <p>Here is my .xml code:</p> <pre><code>&lt;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" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY" android:src="@drawable/lapices" /&gt; &lt;ImageView android:id="@+id/imageView2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY" android:src="@drawable/lapices" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload