view methods setX setTranslationX setTop animate().x() not working - android

I have a relative layour and a imageview inside of it. I want to move the imageview to the touch position.
I have tried these methods for X and Y
view.setX()
view.setTranslationX()
view.setTop()
view.animate().x()
none of them is working, nothing happens.
The code runs inside PagerAdapter. I have an imageview that takes all screen and i set onTouchListener for it, get touch coordinates and set them to another imageview, that is a red circle, to move it to the touch location, but it is not moving at all.

Related

Scrolling in all directions

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

Redrawing clipped content in Android View after moving into bounds

Within Android, I'm trying to move a TextView from outside the parents bounds into view, but the contents never shows up, or remains clipped if it was partially within the bounds already.
Initial situation at start
Situation after animation
(Below this is another view, that was completely out of bounds and isn't drawn either)
I have 4 TextViews below each other in a custom Object extending RelativeLayout. Based on a percentage the top 2 should move outside it's bounds and the bottom 2 should move in (from the bottom).
I use the following code to update the properties of each TextView. In this class each variable **positionY* is filled with their initial position from the layout-xml. effect is percentage between 0 & 1. The animation works, but the views aren't drawn again.
public class ActionBarTitleView extends RelativeLayout {
public void updateTransition(float effect) {
float height = getHeight();
titleView1.setY(title1positionY - height*effect);
detailView1.setY(detail1positionY - height*effect);
titleView2.setY(title2positionY - height*effect);
detailView2.setY(detail2positionY - height*effect);
invalidate();
}
}
What I tried
After some researching I found a few hints what the issue might be, but so far none of the tried options had any effect. Below is a list of things I've found on SO and tried.
Calling invalidate() on the RelativeLayout - No effect.
Invalditing the TextViews - No effect.
clipChildren = false for the RelativeLayout - No effect.
setWillNotDraw = false for the RelativeLayout - No effect. (onDraw is being called)
I haven't tried to solve this with a ScrollView, but I don't want to really, cause that adds another layer in the hierachy for something pretty small.
I thought I understood the drawing logic, but perhaps I'm missing something, so I hope someone might be able to point me in the right direction.
What I ended up doing (September 3rd)
Since no real solution was offered, I tried again and came to the following "fix". I set both second labels to Visibility.GONE, but within the original bounds of the container view. Then when I start the animation, I set their correct values, then move them outside the bounds and finally setting Visiblity.VISIBLE. When the animation progresses the labels roll into view as supposed to. So a fix to the issue, but no real explanation why the TextViews aren't drawn again...

Local Co-ordinate of Image view w.r.t to the root View

I have relative layout as a main View and it has few Image views which are place w.r.t to margin top and margin left. Now I want to check the imageViews opacity or transparent region at the pixel where touch is happened. Say I touched some where 533,240 .. I want to check whether that position is transparent or transculent or opaque.. Since imageview will always be square and i guess there will be part of image will be transparent but it should not be included in onTouch event thats why I aim for this that if i get the position of my touch w.r.t to local co-ordinate of the Imageview then I can give that pixel to the drawable.getTransparentRegion.container(int x , int y )
Explaining further.. .what I am trying to do is I am getting View on click or on touch.. From that view I am getting imageview ....and from that imageview I am trying to get Drawable of that imageview ..I have reached till here ... Now I want to get the touch event position w.r.t to the imageview so I can check it in drawable.getTransparentRegion ? ... I hope you understood
At the end I want to differentiate between the transparent part of the imageView i.e.(not needed part of the Imageview ) and the Transculent part that will be there of the drawable in the imageView...
get coordinates of imageview on window by
public void getLocationInWindow (int[] location),
pass integer array of two size to this method. Invoke this method after layout has been drawn, use location array to get imageview's left and top co-ordinates, add transparent co-ordinates to it, and you will get co-ordinates which can be compared to touchevent co-ordinates.

Need to Draw ImageView on top of another ImageView without using FrameLayout

I have a LinearLayout [Horizontal Orientation] in which I have several ImageView objects side by side. I need to be able to drag the ImageView objects side to side.
I can drag them, but I need to be able to draw them ontop of each other as I am dragging.
So, if I have
(imageA)(imageB) side by side, and I am dragging imageA in the direction of imageB, I need imageA to draw on top of imageB and viceversa.
So far, I can get the dragging done no problem [by extending ImageView, capturing onTouchEvent, overwriting the onDraw method, and translating the canvas] however, as soon as the ImageView is moved, it is clipped because of its bounds. I try setting new bounds for the drawable of the ImageView but that doesn't work either.
How do I draw one ImageView on top of another ImageView [without using FrameLayout] ?
Thanks,

Android - dragging imageview with finger does not update position

I'm using a frame layout and a top/left margin combination to drag an imageview around the screen. I've added all code in setOnTouchListener() of the imageview. The problem is the UI does not get repainted on MotionEvent.ACTION_MOVE and i only see the update when MotionEvent.ACTION_UP is received. How could i force the view to redraw the image at its new position on MotionEvent.ACTION_MOVE ?
You want to invalidate the view. If you can get the ImageView call getParent() then invalidate on the parent and that should force a redraw.
((View)v.getParent()).invalidate();

Categories

Resources