Can you draw a rectangle in a scrollview? If so how? I did some searching and I was not able to find an answer. Specifically, I want the rectangle IN the scrollview so that when I scroll the rectangle moves with the view, as opposed to a rectangle being on top of the scrollview, where the scrollview would scroll under the rectangle and the rectangle would remain on top where it is.
You need to create a class that extends ScrollView and override onDraw(). There you can draw whatever you want. To make the drawing scroll with the content, you should offset the locations with the values you get by getScrollX() or getScrollY().
Related
I am overlapping an ImageView on top of a View in a RelativeLayout.
something like this:
1
Where the middle white circle(ImageView) is overlapping the white vertical border(View).
But for some reason I am not managing to constraint the circle above the z position of the white border. and if the border moves say to the right side of the screen, I want the circle to move there too. but instead the circle always remains in the center regardless to the position of the border.
How do I this in a RelativeLayout?
T.I.A
You can make like:
AlignLeftOf the border
Then code: circle.translationX( circle_width/2)
(and a bit of justification, it should be good)
I've been trying to implement an activity where I can scroll horizontally and vertically in all directions, I've tried out using gesturelistener and the "scrollby" method in View, however the screen is still static. I've also done a nested horizontal and vertical scroll in xml, however this only gives me scrolling to the right of the screen and bottom. It seems i cant move in the negative x direction.
Thanks.
Customize ViewGroup
Override OnTouchEvent
Detect MotionEvents
Track Finger Points
Calculate Distance Moved
Modify the X and Y of the canvas Content Rectangle.
Finally in your layout add child views you want to scroll inside this ViewGroup
Source code: https://gist.github.com/jayakrishnan-pm/ScrollingLayout.java
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!
I'm trying to do a TweenAnimation (Scale and translate) with two ImageViews (top and bottom). Each ImageView (and some other stuff) is in a RelativeLayout and the RelativeLayouts are in a LinearLayout. The images moves to the left top corner of the display. The Animation works fine, but at the end of the (Relative) Layout the animation disappears (in the mid of the display).
Is there any way to give the animation more (all) space then only the parent View? Thanks!
You can set the parent view to not clip it's children and allow them to draw outside it's bounds. In your XML, add this:
android:clipChildren="false"
I want to draw A Rectangle over a Image In Horizontal And Vertical Direction Just Like a Grid.
I can use grid but when I Pan(Drag) image this won't work. The rectangle should also Pan with the Image or shold move with the Image.
The easiest way should be to have a view that draws the shape you want and your image together in a frame layout.
And then you should move the layout of both view rather than the view alone.