Move view to the top of the screen with animation - android

I have following layout:
Three EditTexts in LinearLayout with layout_width = 0.33. When user put focus to one of those EditTexts, two other should dissapear (maybe animation too) and last one should be moved to the top of the screen with some animation meanwhile soft keyboard is shown. Result should looke like this:
Solution without animation is simple:
if(focusedView == mBlueEdit) {
mRedEdit.setVisibility(View.GONE);
mGreenEdit.setVisibility(View.GONE);
I can't figure out, when to start (it's too late start it after GONE is set at other views) and how to compute X and Y positions at start and at the end of animation. Thanks in advance for every hint.

Not sure if it is what you are looking for, but you can create automatic animation by simply adding android:animateLayoutChanges="true" to your LinearLayout.

Related

Why is not working my horizontal scrolling done programmatically?

I'm trying to make horizontal scroll in TextView bRes programmatically. Reading some answers and tutorials, I've included some settings.
bRes.setHorizontallyScrolling(true)
bRes.setMaxLines(1)
bRes.setMovementMethod(ScrollingMovementMethod())
bRes.setScroller(Scroller(this))
I put in the left and right side of TextView, small left and arrows black triangles with a click event to make right and left scroll if text width surpasses the view width. The buttons just appears if they has some action to do.
When I set the text in TextView, I call this code
fun changeRes(t:String){
bRes.text = t
bRes.post{ bRes.scrollTo(0,0) }
val largu = bRes.getPaint().measureText(t)
bRight.visibility = if (largu > 0.99 * bRes.width)
View.VISIBLE else View.INVISIBLE
bLeft.visibility = View.INVISIBLE
}
I've selected put the text excess in the right side, i,e, when the text is wider than TextView, the left black arrow is invisible and the right black triangle is visible.
Well, with this the text disappears completely. If I comment the line
bRes.post{ bRes.scrollTo(0,0) }
the text appears again, but there is no scroll. I don't get to see the left excess characters. The bRes.scrollX value should by 200/300 pixes but is over 1 million!
The first parameter, according documentation, is the number of pixels invisible to left of the TextView.
PS: I've used exactly the same procedure to program a vertical scroll in another TextView and it works very well. I don't use ScrollView, I've directly programmed a scrolling in my another TextView.
PS 2: I've created all my layout dinamically. No XML for layouts.
Somebody has some help for me?
I have no idea about it, except put the text in TextView manually in each change.
What kind of layout are you using? It should not be a LinearLayout, but rather a FrameLayout or RelativeLayout
I've made a workaround that is working very well for me. It's sad that I haven't found a more direct way to do this:
a) I've put 2 triangle arrows inside 2 small buttons to the left and rigth of TextView.
b) The buttons are visible or not depending if has or not scroll hidden text in its respective direction.
c) I've used the event OnTouchListener to accept click in the scroll buttons or 20% of TextView width nearest to each arrow for getting more hidden text in that direction (I've made this because the arrows are small and prone to touching in a wrong place.
d) I have to keep inside a tag (extra field of the widget) a complete text value of the widget.
e) For calculating which text I have to put in a field, I've programmed a heuristic using
widget.getPaint().measureText(string)
The visual is something like this:
PS: The ideal isn't using horizontal scroll, but if it is necessary, I think that the above appearance is nice and it is practical for users. I don't like the marquee solution where text moves alone: thinking as user, it's annoying.

Layout Swiping in Android with fixed button, How to?

I am having great trouble to implement layout swiping UI. Here I show you how each layout works.
My first Layout
My second layout
My third Layout
How it works:
A user can move one page to another by touching the screen and the indicator will move as the layout or page move. But the Sign In and Sign Up button will be fixed in there position. How can I implement this type of UI.
This can be done using a viewFlipper but there is a trick using this whole as a layout.
Use a frameLayout
having your buttons settled down with the gravity set to bottom
Note framelayout works as a stack LIFO things(widgets/layouts) placed at last will superimpose the ones place above them in xml
like for example
//so here view shows s2 and below that s1.....
so in your layout s2 will be the buttons with gravity as bottom
s1 -should be a viewFlipper ...
SWIPPING
swipping can be acheived using the onTouch event
SWIPE LEFT
When the touch down gives a position(x1,y1) and onTouchUp (x2,y2)
check if(x2>x1)
so use viewFlipper.setInAnimation(Animation) viewFlipper.setOutAnimation(Animation)--for the ui that will be gone
SWIPE RIGHT
similarly if (x2<x1)
viewFlipper.setInAnimation(Animation) viewFlipper.setOutAnimation(Animation)
You have used three different layout and increment counter by touching the layout and match to set the layout.
Here is the complete example of ViewFlow please check out the source
https://github.com/pakerfeldt/android-viewflow
and here is another example
http://developer.android.com/shareables/training/Animations.zip
see implementation of screen slide, that is what you exactly want.
The bar moves something like this
Display d= getWindowManager().getDefaultDisplay();
int h=d.getHeight();
int w=d.getWidth();
after getting this h and w , now at every swipe move the bar
where w=screen width calculated with the above method
increments=w/3;
bar_initial_position+=increments;
so it moves..

Android: Keeping Image Visible Throughout Animation

Background:
I have an Activity that comprises four buttons that each take up a quarter of the screen.
It contains a horizontal LinearLayout that is divided in half by two vertical LinearLayouts as shown in the image below:
http://i.stack.imgur.com/P7Wd3.jpg
Desired Effect:
When I touch a button, I would like it to animate and fill up the entire screen.
Issue:
I have accomplished the animation aspect by changing X and Y scales from 1 to 2 onClick.
The problem is, however, that the animated button will not show when it leaves its parent LinearLayout.
Thoughts
I have tried making the non-animated buttons invisible, but the animated button will only show in its parent LinearLayout.
I know this problem would be solved if I had used a single LinearLayout, but I was unable to use the "layout:weight" feature to make each button take up half of both width and length.
So... How should I approach this issue?
I would appreciate any help :)
Try using a single RelativeLayout. Check this post for a nice example. You may have to setVisibility(View.INVISIBLE) for the other buttons.
Alternative:
Construct a RelativeLayout as above but put that as the only child
of a FrameLayout.
When animating a button, remove it from the RelativeLayout and add it to the FrameLayout specifying the gravity in the LayoutParams appropriately. This way the rest of the buttons will also be seen in the background during the animation.

TranslateAnimation, occur on top

I got a question regarding TranslateAnimation. Is it possible to force the the animation to occur
on top of other views? I'm trying to translate the first child on top of the other elements in a LinearLayout.
I thought setZAdjustment would do the job, but it didn't work as expected.
I can see why that wouldn't work as expected.
Try customizing your LinearLayout to one which overrides getChildDrawingOrder() and thereby force it to draw your animated child last.

Vertical smooth scrolling of values in a text view

I have a text view where in i have to keep ages between 1-99. I also have two buttons ^ and v(i mean up and down arrows) on clicking them the values of the age should smoothly scroll to next or previous value.
I have been trying different ways but couldnt achieve smooth scrolling. Can anyone please give me any idea of how to achieve the task.
I think the easiest way is to simply put the TextView within a ScrollView, and let the arrows interact with the ScrollView, by using things like the fling method and playing around with the velocity parameter to suit your needs.
Use the animation framework.
When pressing down, start the 'down'-animation.
When pressing up, start the 'up'-animation.
Read more about animation here: http://developerlife.com/tutorials/?p=343
View animation is not much matured and hence i am noy sure if that can be used for moving the views.
Please find the description below:
Another disadvantage of the view
animation system is that it only
modified where the View was drawn, and
not the actual View itself. For
instance, if you animated a button to
move across the screen, the button
draws correctly, but the actual
location where you can click the
button does not change, so you have to
implement your own logic to handle
this.
Source
To scroll smoothly you can try using the scroller component.
Reference
What you would need to do is pass the duration of the scroll in the constructor and then use the property
setFinalY(int newY)
to increment the counter position by 1 unit (equal to the height of the item).
Please let me know if that helps!

Categories

Resources