RelativeLayout onDraw - android

I create a subclass of RelativeLayout,the use of it in the layout file.In the layout file also defines some components widget.Overwrite the OnDraw painted a picture,The picture can not draw on the top, but the control block.
Like this:
How do I get the picture to the layout of the above.the picture is and move according to the finger movement..thanks.

Related

How should I draw lines out of bounds of the button like attached picture?

I want to draw a custom button with red bounds, where lines are out of bounds of the button like the image below.
If it is appropriate you can draw a picture (like one attached to your question) and use it.
You can use picture as a sourse for ImageView element. Then use this ImageView as a button (set onClickListener to it).
You can also try to create layout (FrameLayout or RelativeLayout) and use your picture as a background for that layout. Then put a Button element inside that layout. Try different width, height, margin, padding properties for Button and layout to place Button inside red rectangle made with red lines.

Android Custom ViewGroup add one child before drawing others

I have a custom ViewGroup that contains an ImageView and a few other TextViews that display white text on the image. I would like to draw ONE dark rectangle under all the textviews to improve the contrast.
To accomplish this, in the custom ViewGroup's onLayout, I compute the smallest rectangle that contain all of the TextViews. Now, I have no idea how to draw the rectangle on top of the first child (the image), but below the other children, the TextViews. So I would like to draw the children in the order:
ImageView (first child)
Computed dark Rect
TextViews (all other children)
I tried overriding dispatchDraw() and then after the call to super.dispatchDraw(canvas), I drew the rectangle. But that obviously put the rectangle over the TextViews.
I would appreciate any help.
Thanks!

Android FingerPaint SDK sample use as text/image highlighter

What I want to archive is, highlight a text or an image as we do in PDF or any other doc editor.
What I am doing is, in my xml layout I have added a TextView, ImageView, WebView in an RelativeLayout and depending on the type of the contents to be displayed, I change the visibility of the one, for example if I have an image to display then I set the image Path to ImageView and set it is as visible and others as invisible.
For drawing highlight, I am trying to use Android SDK demo FingerPaint.
On Top of all these views I have MyView, which draws the highlight, which is from FingerPaint SDK demo, I have made the canvas transparent so I am able to see widgets below MyView.
Questions that I have:
I am not able to get what is the use of mCanvas = new
Canvas(mBitmap); in onSizeChanged method, as mCanvas is not added to view, when I remove it then old lines that i draw does not display on the screen.
How to change the line size and make color of the line semi transparent, so that view below MyView is visible from the line.
How to draw only straight lines (Vertical/Horizontal).

How to make a blur transparent linear layout

I have a transparent layout in android, and behind the layout there is an image. how to make the linear blur ? I found examples to make the image itself blur but I don't want to make whole image blue, just only the part that is behind the linear layout.
Set a semitransparent Blur image to the linear layout or simplest set a color to linear layout and set it to semitransparent by defining alpha
edited solution
do this...
1.) create a blur copy of the image u have on background.
2.) clip the image by using
Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, startX, startY, widthLayout , heightOfLayout);
3.) set this image in the Linear Layout using an image-view with height and width attribute as fill-parent.
I have pretty complex solution, so there won't be any code. So, here is idea, step by step:
Let's assume that your layout have just single custom LinearLayout. No ImageView as a background.
What we going to do, is draw background drawable of LinearLayout by our own, so it will first draw full image and then draw blurred square from the same image on top. Content of LinearLayout might be moved to desired position using paddings.
So, create something like MyLinearLayout and put it to your layout resource. Provide required constructors.
Override onAttachedToWindow() and onDetachedFromWindow() methods. Inside them we should load our background Bitmap and recycle it accordingly. Let's name it mBackground
Override draw() method. Inside it we're going to first draw our mBackground.
Then, you can use Canvas#clipRect() method to crop drawing area of Canvas to some specified rectangle. In your case, this rectangle should be the area below your content. You can figure it out using View#getPadding*() methods. Don't forget to call canvas#save() before clipping drawing area.
Now you can draw your bitmap once again with blur (I don't know which method exactly you're using, so let's assume that you know how to do it... but you still can share it with us :) ). Cool thing is that you can just draw the same Bitmap once again in full scale - since we had called clipRect before, it will be drawn only within this area. Don't forget to call canvas#restore() after drawing background.
Call super.draw() to draw rest of the stuff, that your LinearLayout contains.

drawing layout through canvas

I have a layout like :
<ll vertical>
<ll horizental>
<textview></textview>
<textview></textview>
</ll>
<ll horizental>
<textview></textview>
<textview></textview>
</ll>
</ll>
The problem is i need to display this as part of my whole screen.
i am doing
mCustomDrawableView = new CustomDrawableView((Context)this, R.drawable.mychart);
setContentView(mCustomDrawableView);
and on ondraw of my custom view i am drawing the bitmaps etc.
The problem is how can I make above layout into a ibitmap, so that I can draw it in this custom drawing ?
I need to do this because in the layout, one TextView will have right aligned text which is difficult to do in custom drawing.
You should be able to inflate the layout and build the paramaters/child-text-views you want. Then, create a Canvas from your own Bitmap and call the layout's 'draw' function passing in your own canvas. The layout should then blit all of it's children into your custom bitmap, which, you can then do whatever you want with.
http://developer.android.com/reference/android/view/View.html#draw(android.graphics.Canvas)

Categories

Resources