android resize animation - android

Is there a way to apply a 'resize' animation as opposed to a scale animation in Android? When using the scale animation, the image or layout being resized is stretched out, this includes the border / stroke outline that is outlines the image. I have a box, with 2 lines around them, when the animation is applied the stroke appears to grow, this is likely due to the fact that the 'scale' animation is actually scaling the borders/strokes in addition to the drawable. Is there any way to have the box grow, without having the stroke/border/outline appear to grow as well? i.e. i just want to resize, but not necessarily 'rescale' the drawable. note, my drawable is defined in xml...

I would suggest removing the borders from the image and instead draw this border by wrapping your ImageView with a LinearLayout. Use some padding to create the borders and set the background color of your LinearLayout to apply the border appearance desired.

The default animation tools in Android do not provide a way to perform resize animations. Your best bet is to have a TimerTask that changes the dimensions of the view on the UI thread at specified time intervals.

Related

How do I create a layout w/ a white background, grey border with a triangle arrow - Android

How would I replicate this in Android, my general instinct would be to create a regular layout w/ a border, then have 2 layouts that contain a triangle (one the same color as the border + one that's slightly smaller but white and overlap the two), idk if there's an easier way to do that:
You can use 9patch to achieve something like you wanted.
The Draw 9-patch tool is a WYSIWYG editor that allows you to create
bitmap images that automatically resize to accommodate the contents of
the view and the size of the screen. Selected parts of the image are
scaled horizontally or vertically based indicators drawn within the
image.
A complete guideline can be found here : http://developer.android.com/tools/help/draw9patch.html
The easiest way to reach this, is to set the layout background to that image.
background="#drawable/template"
Probably you want to have the area out of the "bubble" transparent, so you will need to save it as PNG.

It is possible to move a tiled background? (infinite scroll with TileMode.REPEAT)

I am developing a game
First of all my game will be very simple, so i would prefer not to use libraries or opengl or canvas, i would prefer to achieve this with simple imageviews or normal views, or at least by the simplest way possible. For example with android bitmap tile mode:
public static void setBackground(Bitmap bmp, ViewGroup layout){
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
layout.setBackgroundDrawable(bitmapDrawable);
}
I want to develop a simple 2D/3D hybrid spaceship game. The screen will be the vision from the spaceship cockpit, and you will move the spaceship touching a joystick that i have allready done. So the background will be a universe background, i mean a huge black image with stars, and this image must be moved to all directions with the joystick simulating that the spaceship is changing it's direction, and when you move a lot to the right for example, the background image must start from the begining to simulate that the space ship is still moving to the right without any limitation
As i have mentioned, i have the joystick now, and i know how to move a imageview with the joystick, the problem is that i dont know how to create a infinite imageview with tiles correctly, because when i move the background containing the tile imagedrawable then the image dissapears from the screen.
This is an example of an image for using with the infinite background:
I had a similar problem and found a solution which uses only XML. In a vertical ScrollView that has a height of 50000dp, my tiled background image repeats as much as needed to fill this height. As a result, scrolling would create the desired effect of stars flying by (using your image as an example).
Use a ScrollView, its background does not matter. Height set to wrap_content.
Inside this ScrollView, place another layout (I happen to have a ConstraintLayout). This is the background that matters. Height set to wrap_content. Set the background of this to: android:background="#drawable/repeating_background"
Create a new drawable called repeating_background.xml with the following code:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/stars_image"
android:tileModeY="repeat"
/>
where tileModeY="repeat" makes stars_image (png, jpeg, etc.) repeat only vertically. You would want to use tileMode="repeat" since that can handle X and Y. tileMode="mirror" is something you could explore since it reflects the image to get rid of the appearance of any seams if the background color changes.
That's it! If you had set this same background to the ScrollView itself, then it would simply tile your image, but this tiled background would remain static while the contents of your ScrollView scrolled.

image animation cropped by layout bounds

I have an image that gets scaled from large to small as it spins. It's mean to be a fancy animation to simulate a tile being place on a board. The animation works as expected except for one thing: This image is cropped.
Each row of tiles is inside of a Horizontal LinearLayout. Each LinearLayout is inside of another LinearLayout (Vertical). This give the board. Sadly, the image animation is getting cropped to not excede the bounds of the parent layout. I don't want that. I want the image to be displayed and animated as if it's on top of everything else. I want it to exceed the layout.
Any idea how to fix this?
Here's a couple of screenshots:
Your image is constrained to fit within it's parent view as per design. You might want to use a canvas to hold all your tiles instead (keep in mind the bounds of the canvas for the corners otherwise you will have the same issue), or look into other layouts that might be able to accommodate your needs.
From: http://developer.android.com/guide/topics/graphics/view-animation.html
Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.

How to center a background tile?

I'm trying to create a tiled background for a match_parent-wide container, where the tile is repeated from the parent's center, not from its left edge. I want this in order for the background to always appear centered regardless of screen width.
I noticed that Android's BitmapDrawable has a gravity attribute, but it seems to have no effect when tileMode is set to repeat or mirror. I would have expected that the bitmap is first centered in its container, then repeated outwards from the center point. Instead, it's still left-aligned and then repeated, resulting in the first tile always be fully visible but the last tile being cut off unless the screen width is a multiple of the tile's width.
UPDATE: Just noticed, "Gravity is ignored when the tile mode is enabled." (tileMode attr docs.) Any other ways to achieve this?
I think this post might be interesting to you. Basically gravity doesn't work with tilemode (as we've already established) but you could create a matrix of your images and use that to create the background of your desire. So basically build the tilemode in code yourself.

Android: Stretching ImageView with background

I have a landscape layout that features a vertical LinearLayout of buttons on the left side of the screen and a user-defined picture on the right of the screen. The design I'm working from calls for a double-stroke border around it, which I implemented by creating a rectangular shape background with the border being the outer color and the background of the shape being the inner color. I then just put some padding around the picture, and you get the double-stroke border. The problem is expanding the picture to fill the space in the layout. I don't know the dimensions of the picture, since it is user defined, and I'd like it to expand to exactly fill either dimension while preserving the aspect ratio. Setting fill_parent for both width and height does that, but it also expands the background all the way to completely fill the cell, resulting in a sort of letter boxing effect. Is there any way, short of just adjusting the size of the view after layout, of getting this to only expand the view as much as necessary?
I never got this to work properly, and just ended up adjusting my layout to a different arrangement.

Categories

Resources