I am trying to show a fragment with right to left animation, as though it is coming from the right side of the screen but my code does exactly the opposite.
flBackground.animate().setDuration(250).x(0).translationX(0).alpha(1).start();
flBackground here is the id of the root view in my fragment.
I played with 'translationX' method. I gave the screen width in pixels, but my fragment got off screen. Is there a way in ViewPropertyAnimation that I can set initial positioning of a view to animate from?
I only want to use ViewPropertyAnimation, not other Animation objects. Other ones are quite big and I want simple code for my project.
You can use FragmentTransaction.setCustomAnimations(). It's the best way.
Example:
getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.slide_right, R.animator.slide_left)
.add(R.id.list_fragment_container, YourFragment.instance())
.commit()
More: https://developer.android.com/reference/android/app/FragmentTransaction#setCustomAnimations(int,%20int,%20int,%20int)
Related
I am attempting move a Button around in an Android app I'm making (Java). Under certain circumstances in onResume(), I get margin information about the button, then attempt to place the button at the left edge of the screen with that margin as a slight gap so it looks nice. See below.
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) button.getLayoutParams(); button.setX(lp.leftMargin);
However, apparently the information in my xml layout file gets read AFTER I programmatically set the button position. So, my button is getting placed exactly in the middle of the screen (as stated in xml file) PLUS 8 dp to the right. I need a way to reorder these positioning commands -- Anyone know how to queue up a dynamic view placement in onResume so it delays just enough to occur immediately after the button is done being placed by my layout file?
Found it!! I guess it was a duplicate question, I couldn't find it searching before:
https://stackoverflow.com/a/24035591/14116101
I'm trying to set OSM fullscreen adding a onTouchListener on the MapView, calculating the time between touch down and up, and setting a FLAG_FULLSCREEN. but this is not working well since other views on the activity and some items of ItemizedOverlay type are triggering the OnTouch.
Well, i really tried to make this work this way, but everything i tried i had the same result. Other items in screen triggers the OnTouch. There is some other way to make a fullscreen OSM?
Don't know exactly what to show about my code, because it's very simple and explained above. But if needed, i post here.
I've got a view which I am trying to get its location after its drawn.
Below is the code I'm using for that.
view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener{
#Override
public void onGlobalLayout(){
int[] location = new int[2];
view.getLocationOnScreen(location);
Log.d("SOME TAG","Location is ("+location[0]+","+location[1]+)");
});
the above code gives me 0,75. Great, except if i place an onClickListener there to get the location of the click (on the top left corner) I get 0,275.
Whats interesting is that if i do that same process in the onClickListener, I get 0,275 for the top left corner. Any clues on what I am doing wrong, or if there is a better place to put the code to fetch the location. It has to be after the view is drawn (for obvious reasons).
Thanks!
There are several ways to approach this problem. I am not sure what the end goal here, but here are they:
Extend view and override onDraw for example or any other method you need
Like you said, call it onClick, since by that time UI is layout and rendered properly
I have a vertical LinearLayout which has two another vertical layouts inside. The first one is always shown, and the second one depends on some event. I do want to animate that second layout when shown. How can I do it smoothly and nice? Thank you so much,
You should check out this library on Github. It may help. It is an animation library for listviews.
ListViewAnimations
A very simple, yet elegant way to get your layouts animated is by using the android:animateLayoutChanges="true" on its parent. This will likely take a lot of work in getting a nice animation out of your hands, unless you want to customize it.
With KitKat, Google introduced the android.transtion API, which may also be worth looking at.
You can create your own animation and you apply that animation to your layout when you need(In your case at the time of shown your layout)
yourLayout.startAnimation(yourAnimation);
I want to programatically scroll a View. So far, I have found two possibilities :
scrollTo(x,y) : the top left hand corner of the View corresponds to the point (x,y) of what must be drawn in the View. The problem is that, after the call, it is impossible to manually scroll the View to have it displays what is above y or what is at the left of x.
setScrollY(y) : seems to be the function I'm looking for. But it is only available for API above level 14. And my application is supposed to work with API level 8.
Is there another function which could do what I want to do?
Thanks in advance for the time you will spend trying to help me.
Is your View in a ScrollView? If not, you will need to handle events yourself to manually scroll the View after you use code to set the scroll location. It sounds like you want both manual and programmatic control, so you'll need to use a scrolling container or handle touch events yourself.