I have mostly stolen some code for drag and drop in a list view from
the android music app, which is here:
http://www.netmite.com/android/mydroid/cupcake/packages/apps/Music/src/com/android/music/TouchInterceptor.java

Somehow with my implementation I can not get the transparency and
background color to work. It seems like the call to
v.setBackgroundColor(Color.LTGRAY); has no effect. Also in the sample
code from the music app the bitmap is partially transparent but on
mine it is a solid black background. I replaced:
          int backGroundColor = mContext.getResources().getColor
(R.color.dragndrop_background);
          v.setBackgroundColor(backGroundColor);
with
          v.setBackgroundColor(Color.LTGRAY);

In the sample code they instantiate a TouchInterceptor as part of a
ListActivity, but in my case I just use a list view in a class that
has been extended from Activity.

I can load a different bitmap then the one passed to the function and
that works fine, but I still get a solid black background on the view.
I am suspecting that it may have to do with the line that gets the
windowManager:
windowManager = (WindowManager)context.getSystemService("window");
since in my case I am not using a ListActivity. But I am really
stumped, if anybody has any suggestions for what I could investigate
or do it would be appreciated.


This is my function:
        private void startDragging(Bitmap bm, int y) {
            windowParams = new WindowManager.LayoutParams();
            windowParams.gravity = Gravity.TOP;
            windowParams.x = 0;
            windowParams.y = y - dragPoint + coordOffset;

            windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
            windowParams.width  = WindowManager.LayoutParams.WRAP_CONTENT;
            windowParams.flags  =
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                                                | 
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                                                        | 
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                                                        | 
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
                windowParams.format = PixelFormat.TRANSLUCENT;
                windowParams.windowAnimations = 0;

                ImageView v = new ImageView(context);
                //Bitmap bm = 
BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon);
                v.setBackgroundColor(Color.LTGRAY);
                v.setImageBitmap(bm);


                if (dragBitmap != null) {
                        dragBitmap.recycle();
                }
                dragBitmap = bm;

                windowManager = 
(WindowManager)context.getSystemService("window");
                windowManager.addView(v, windowParams);
                dragView = v;
        }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to