android - Setting one of 2 ImageViews transparent/invisible, shows white screen -


i newbie , have been working on couple of days without success. somebody's appreciated.

i have 2 imageviews, 1 behind other in activity. make first 1 (the 1 @ top), invisible or transparent, can use internally in code. second 1 (the 1 on bottom), should remain visible, user can interact it. tried doing setting canvas transparent first, , top imageview, causes screen show white color, instead of showing imageview behind (the bottom one). please, explain me why happening, , suggest me better approach achieving purpose? in advance.

here .java 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;             }         }); } 

}

here .xml code:

<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> 

i don't see trying achieve. , should exist better way, far can see if turn linearlayout in relativelayout , change order of image views should work.

by way code.

<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> 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -