android-canvas
SurfaceView flashes black on load
I think I found the reason for the black flash. In my case I’m using a SurfaceView inside a Fragment and dynamically adding this fragment to the activity after some action. The moment when I add the fragment to the activity, the screen flashes black. I checked out grepcode for the SurfaceView source and here’s … Read more
PorterduffXfermode: Clear a section of a bitmap
The problem is hardware acceleration. Turn it OFF for the particular View that you are painting with CLEAR. If you’re using a custom view, do this in the constructors: if (android.os.Build.VERSION.SDK_INT >= 11) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } You can also call setLayerType on a view reference.
Adding a colored background with text/icon under swiped row when using Android’s RecyclerView
I was struggling to implement this feature as well, but you steered me in the right direction. @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { // Get RecyclerView item from the ViewHolder View itemView = viewHolder.itemView; Paint p = new … Read more
Understanding how actually drawRect or drawing coordinates work in Android
canvas.drawRect(left,top,right,bottom,paint); In this left: distance of the left side of rectangular from left side of canvas. top:Distance of top side of rectangular from the top side of canvas right:distance of the right side of rectangular from left side of canvas. bottom: Distance of the bottom side of rectangle from top side of canvas.
Android: Drawing a canvas to an ImageView
I had the same challenge and came to the conclusion that overwriting onDraw will at least in the general case not work. My blog explains the reasons. What worked very well for me is the following: Create a new image bitmap and attach a brand new canvas to it. Draw the image bitmap into the … Read more