Android slide up window - java

Can anyone point me to an example, or a lib to use for a slide up window. I have an app and on an action I want to slide a window up from the bottom of the screen that displays info to the user.
I would like the window to slide up only a little bit to show the info. Kind of like a hnt to the user, maybe 1/4 way up the screen.
This window can be manually dismissed or on a timer. I am looking to do this with xamarin, but a java example would also help.

You might have to change some of the variables in this method.
I use this one in one of my apps. Animates a relativeLayout from bottom to top
private void animate(){
RelativeLayout rl = (RelativeLayout)findViewById(R.id.yourLayout);
AnimationSet set = new AnimationSet(true);
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.85f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(250);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);
rl.setLayoutAnimation(controller);
}

Related

Android - Two ScaleAnimation played sequently

I want to make simple animation where ImageView is zooming out, and after this, zooming in, and will be grate to change that image when it is invisible. I started with this code:
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation oldOutScaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
oldOutScaleAnimation.setDuration(500);
animationSet.addAnimation(oldOutScaleAnimation);
ScaleAnimation newInScaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
newInScaleAnimation.setDuration(500);
newInScaleAnimation.setStartOffset(500);
animationSet.addAnimation(newInScaleAnimation);
view.startAnimation(animationSet);
But I don't see animation, I see only:
Image
Image Disappeared
Image Appeared
There is no transtion.
Each of this animation separately works.
I don't want to do this in XML.
Thank you for any reply.

Libgdx / Scene2D Scaling not working

im currently developing a little duengon crawler and i wanna try to implement a healthbar using Scene2D. But theres a problem ... when i try to set the size of the progressbar its ever and ever the same size, doesnt matter if i do :
healthBar.setWidth(1f);
healthBar.setHeight(0.25f);
or
healthBar.setWidth(100);
healthBar.setHeight(25);
What im doing wrong ?? Heres how i created the stage ^^
camera = new OrthographicCamera(0,0);
camera.setToOrtho(false,Gdx.graphics.getWidth()/Box2dVars.UNIT,Gdx.graphics.getHeight()/Box2dVars.UNIT);
camera.zoom = (float) 0.75;
port = new ExtendViewport(camera.viewportWidth, camera.viewportHeight, camera);
stage = new Stage(port);
I also act and draw the stage every tick in the render method. Heres how i create the ProgressBar :
skin = new Skin(Gdx.files.internal("Scene2D-Skins/uiskin.json"));
healthBar = new ProgressBar(0, 100, 0.5f, false, skin, "default");
healthBar.setWidth(1f);
healthBar.setHeight(0.25f);
healthBar.setPosition(this.getPosition().x, this.getPosition().y);
this.gameScreen.stage.addActor(healthBar);
Did you see a mistake ?? What did i forgot ? :/ I would be happy about some help !

Android Collision Detection?

Here is the code that I use for the moving ImageView:
int x=brickimg.getRight()-brickimg.getLeft();
int y=brickimg.getBottom()-brickimg.getTop();
final TranslateAnimation translate = new TranslateAnimation(
Animation.ABSOLUTE,x1, Animation.ABSOLUTE,
-2000, Animation.ABSOLUTE,0,
Animation.ABSOLUTE,y);
translate.setDuration(1200);//speed of the animation
translate.setFillEnabled(true);
translate.setFillAfter(true);
//brickimg.startAnimation(translate);
//2nd brick animation
int x1=brickimg2.getRight()-brickimg2.getLeft();
int y1=brickimg2.getBottom()-brickimg2.getTop();
final TranslateAnimation secondone = new TranslateAnimation(
Animation.ABSOLUTE,x1, Animation.ABSOLUTE,
-2000, Animation.ABSOLUTE,0,
Animation.ABSOLUTE,y1);
secondone.setDuration(1200);//speed of the animation
secondone.setFillEnabled(true);
secondone.setFillAfter(true);
This is for two images. Here is the code that I tried to use for collision detection:
Rect rc1 = new Rect();
brickimg.getDrawingRect(rc1);
Rect rc2 = new Rect();
playerimage.getDrawingRect(rc2);
if (rc1.intersect( rc2)) {
playerimage.setVisibility(View.GONE);
}
However, the only thing that happens is that playerimage turns invisible when the app starts. It doesn't turn invisible again. One of the images doesn't move, and the other moves across the screen towards the one that doesn't move (using the code I put above). The image that doesn't move turns invisible immediately, and not when the second image touches it. I'm trying to make it so it does something when it touches the moving image. Besides this, I've also tried .getHitRect and I've also tried .intersects instead of .intersect, but none of it works. The moving image is an ImageView, not a sprite. Is there another option?

Rotating an image to specific direction

I am trying to rotate an arrow to point to some specific location
float bearing = myLoc.bearingTo(mecca);
RotateAnimation rotate = new RotateAnimation(0, bearing, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
arrow.setAnimation(rotate);
rotate.start();
However it rotates and within less than one second it comes to its original place. How can i make it rotate like a compass.
Another simple way to rotate an imageView :
Matrix matrix=new Matrix();
imageView.setScaleType(ScaleType.MATRIX); //required
matrix.postRotate((float) angle, pivX, pivY);
arrow.setImageMatrix(matrix);
Did you tried :
rotate.setFillAfter(true)
Just try To set Duration Of Your Animation, like
animation.setDuration(1500);
Where Duration is int(miliseconds)

AndEngine GLES 2 - black screen, no errors

I am writing a game for Android using AndEngine GLES 2. Everything was working properly - I had a background image, there were sprites moving around and even some music - until recently I tried something new (I wanted to be able to switch between two different scenes) when the display turned black.
I could still execute the game and there were no error shown. All log entries I made during the game were shown, even the music was playing so I knew the game was running "properly", but I couldn't see any image. Nothing. All black.
So I thought, changing everything back to before this "error" appeared, would do the trick. But still the screen is black.
I even tried commenting everything out but the background image - nothing.
Now if it is not too much to ask, could anyone please look over this short piece of code and tell me what is wrong there?
This are the variables I use:
private SmoothCamera camera;
private BitmapTextureAtlas bitmapTextureAtlas;
private Scene scene;
private Sprite background;
The EngineOptions I never changed, so they should be alright.
#Override
public EngineOptions onCreateEngineOptions() {
float positionX = 80f; // horizontal (x) position of the camera
float positionY = 280f; // vertical (y) position of the camera
float velocityX = 200f; // velocity of the horizontal camera movement
float velocityY = 200f; // velocity of the vertical camera movement
float zoomFactor = 1f; // the camera's zoom Factor (standard := 1)
this.camera = new SmoothCamera(positionX, positionY, this.getWindowManager().getDefaultDisplay().getWidth(), this.getWindowManager().getDefaultDisplay().getHeight(), velocityX, velocityY, zoomFactor);
EngineOptions options = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(this.camera.getWidth(), this.camera.getHeight()), this.camera);
return options;
}
Here I create the TextureAtlas and load a background image.
#Override
protected void onCreateResources() {
// create the TextureAtlas
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.bitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1600, TextureOptions.NEAREST);
// background
this.background = new Sprite(0, 0, BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.bitmapTextureAtlas, this, "background.png", 0, 0, 1, 1), this.getVertexBufferObjectManager());
this.mEngine.getTextureManager().loadTexture(this.bitmapTextureAtlas);
}
And finally the Scene is instantiated and the background gets attached.
#Override
protected Scene onCreateScene() {
this.scene = new Scene();
this.scene.attachChild(this.background);
return this.scene;
}
Now why would this small Activity not show? I forgot: its a SimpleBaseGameActivity.
Well, since AndEngine GLES2 is not running on the emulator, I have to use my phone (Samsung Galaxy GIO) and can't test the app on another machine.
Did anyone stumble upon a similar problem?
Any help is really much appreciated and thank you for your time !
Christoph
I think the problem is here:
this.bitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1600, TextureOptions.NEAREST);
The dimensions of the Atlas are supposed to be powers of 2.

Categories

Resources