Hi i want to reduce the length of the edittext view to 3/4 of the screen by animation. Help me on this and below is my code to animate. But it does not happen to move. I want to move it from right to left. Help me please thanks in advance
below is my code
private void animate() {
initialLength = etSearchText.getWidth();
currentLength = initialLength - ibtnSearch.getWidth();
ScaleAnimation anim = new ScaleAnimation(initialLength, currentLength,0, 0);
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(3000);
etSearchText.startAnimation(anim);
initialLength = currentLength;
}
If the above code is called in the onCreate method, you'll find that ibtnSearch.getWidth() is equal to 0. Elements only gain a size after the onResume method I believe. Try temporally hardcoding the size of the search button to see if the animation works or not
Also you'll need to change the scale constructor used to change the point of scaling
try new ScaleAnimation(1, 0.75, 1, 1, 0, 0); Note that the scaling is done by factor terms, not pixel difference.
Related
I created a simple game where move the objects from one place to another and each moves increment count of moves in score table. After all objects are moved correct I want set opacity to screen and slowly resizing score from initial size(e.g. 15px) to whole screen(e.g. 50px). I load font like this:
FontFactory.setAssetBasePath("font/");
final ITexture mainFontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
font = FontFactory.createStrokeFromAsset(activity.getFontManager(), mainFontTexture, activity.getAssets(), "font.ttf", 15, true, Color.WHITE, 2, Color.BLACK);
font.load();
In createScene() method I create HUD with text and I initial text:
Int mMoves = 0;
HUD gameHUD = new HUD();
Text mText = new Text(25, 25, font, "Moves: " + "123456789", getVertexBufferObjectManager());
And each moves set text with actual moves count:
mText.setText("Moves: " + mMoves++);
And when level was complete I don't know how can I resize this text. I mean something like scale with transition in CSS3..
Thanks for all comments
You can set the size of the text by using the setscale function.
If you just want to set the size use the following :
Example : mText.setScale(1.5f);
You can also use Entity modifiers to create an animation:
ScaleModifier scale = new ScaleModifier(1f, 1f, 1.1f);
LoopEntityModifier loop = new LoopEntityModifier(scale);
mText.registerEntityModifier(loop);
This will give a animation effect re-sizing the text in a loop.
For an android app, Im doing infinite Translate Animation.
imageview starts first and after a delay of 1 second, imageview2 starts.
Animation animation = new TranslateAnimation(0, 0, -500, 500);
animation.setDuration(4000);
imageview.startAnimation(animation);
animation.setRepeatCount(Animation.INFINITE);
Animation animation2 = new TranslateAnimation(0, 0, -500, 500);
animation2.setDuration(4000);
imageview2.startAnimation(animation2);
imageview2.setStartOffset(1000);
animation2.setRepeatCount(Animation.INFINITE);
The problem is that, after sometime imageview overlaps imageview2.
What Can I do to avoid the overlapping of 2 images ?
Any pointer would be appreciated.
You might want to try something like this:
private boolean isViewOverlapping(View firstView, View secondView) {
int[] firstPosition = new int[2];
int[] secondPosition = new int[2];
firstView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
firstView.getLocationOnScreen(firstPosition);
secondView.getLocationOnScreen(secondPosition);
int r = firstView.getMeasuredWidth() + firstPosition[0];
int l = secondPosition[0];
return r >= l && (r != 0 && l != 0);
}
This is a method that will take in two views and check whether they are overlapping. If they are, it will return a boolean of true. I would presume that once you get this boolean returned as true, you would then want to carry out another action to ensure they are not overlapped anymore, such as moving one view down 400 pixels. This would then result in the images not overlapping and you would have avoided the worrying situation. Hope this helps!
I have two animation with different duration like below:
Anim 1:
TranslateAnimation trans1 = new TranslateAnimation(0, 0, 0, 500);
trans1.setStartOffset(0);
trans1.setDuration(5000);
trans1.setFillAfter(true);
Anim 2:
TranslateAnimation trans2 = new TranslateAnimation(0, -100, -200, -200);
trans2.setDuration(200);
trans2.setRepeatCount(25);
trans2.setFillAfter(true);
As you see these animation have different durations. I would like to animate Anim2 (duration 200) in loop 25 times during one time Anim1 (duration 5000) animation from Y: 0 to 500.
I've tried to do with AnimationSet and addAnimation but it doesn't want to work.
Could You give me some tips how can I solve this problem?
My code:
AnimationSet rootSet = new AnimationSet(true);
rootSet.setInterpolator(new AccelerateInterpolator());
rootSet.setRepeatMode(Animation.INFINITE);
rootSet.setRepeatCount(200);
rootSet.setDuration(5000);
rootSet.setFillAfter(true);
TranslateAnimation trans1 = new TranslateAnimation(0, 0, 0, 500);
trans1.setStartOffset(0);
trans1.setDuration(5000);
trans1.setFillAfter(true);
rootSet.addAnimation(trans1);
AnimationSet rootSet2 = new AnimationSet(true);
rootSet2.setInterpolator(new AccelerateInterpolator());
rootSet2.setRepeatMode(Animation.INFINITE);
rootSet2.setRepeatCount(200);
rootSet2.setDuration(200);
TranslateAnimation trans2 = new TranslateAnimation(0, -100, -200, -200);
trans2.setDuration(200);
trans2.setRepeatCount(25);
trans2.setFillAfter(true);
rootSet2.addAnimation(trans2);
rootSet.addAnimation(rootSet2);
iv.startAnimation(rootSet);
EDIT:
When I play only trans2 animation it repeats 25 times as I wanted (in horizontal way).
And additionally I would like this animation to animate (whole horizontal animation not only imageview) in vertical way (trans1).
I hope that this description will be clearer.
When I added these two animations in one AnimationSet the first animation doesnt work at all and imageview (not animationn) is translated linear to -200,500.
Now I see what you want to do. You probably are better of doing multiple animations - one for each "line". Add an AnimationListener to know when the previous Animation ends (onAnimationEnd callback), jump down one line and go from right to left again.
They all basically are the same, just the fromYDelta and toYDelta values would change for each Animation.
I have a fragment which is animating from right to left. I want to set it to stop at like 100 units from the left part of the screen. This is what i did so far.
RelativeLayout tempLi;
Display display = MyActivity.context.getWindowManager().getDefaultDisplay();
final int width = display.getWidth();
tempLi.setLayoutParams(new LayoutParams(width-100, LayoutParams.FILL_PARENT));
This line of code is getting the layout 100 units short from the right side. I tried doing -width + 100 , it didn't work.
Any suggestions will be appreciated. TIA
You can set the left-margin to the layout as follows:
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layoutParams.setMargins(100, 0, 0, 0);
tempLi.setLayoutParams(layoutParams);
I'm using an AnimationSet to do many Translate animations. In this example I want to move an ImageView from 0 to 700 (offscreen) and from -700 to 0 (the view move to the extreme right and re-enter from the extreme left). I use this code:
AnimationSet set = new AnimationSet(true);
set.setInterpolator(new AccelerateDecelerateInterpolator());
set.setFillEnabled(true);
if(traject!=null){
TranslateAnimation tmpAnim = null;
set.setDuration(duration);
int d = traject.size()!=0 ? duration/traject.size() : duration;
for(int i =0; i<traject.size();i++){
tmpAnim = new TranslateAnimation( traject.get(i).getStartX(),
traject.get(i).getEndX(),
traject.get(i).getStartY(),
traject.get(i).getEndY() );
tmpAnim.setDuration(d);
tmpAnim.setFillAfter(true);
tmpAnim.setStartOffset(d*i);
set.addAnimation(tmpAnim);
}
}
traject is an arraylist holding each TranslateAnimation start and end points
But in my test example the animation goes from -700 to 700. I tried switching the order of the TranslateAnimations, using setStartTime() instead of setStartOffset(), skipping the call to setStartOffset(), the result is the same. Do you have any idea on what I am missing ?