Android Drawable with fixed size element in center - android

I'm trying to create a placeholder drawable, which should contain a animated image in the center. However, I'd like the center item to be of a fixed width and height. Is this doable?
This is the animated center image XML:
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/loading"
android:pivotX="50%"
android:pivotY="50%"/>

Related

Android - Rotate background and repeat image to fill all the screen

My purpose is to apply a bg to my main view, rotate by xxx degrees and make it repeat in order to fill all the screen, no matter the resolution of the device.
It seems i could make it rotate BUT it doesn't repeat as i wish. I think Android calculate the bg image, then it rotates.
The result is the following. Empty areas on top right and bottom left corners.
and this is the xml generating the bg
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="-20"
android:pivotX="50%"
android:pivotY="50%">
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/cropped_bg"
android:alpha=".20"
android:tileMode="repeat"
android:gravity="center"/>
</rotate>
Can somebody help me?

How to I prevent squeeze of item inside layout during scale animation?

I am using scale animation in Android relative layout , where I have a button and need to scale it to small size at one end .
I have used scale animation and it works fine , but it does have an icon which gets squeezed and its shape gets altered .
I want to prevent it and let the button take its shape without affecting the icon shape when it scales from left to right.
How can I achieve this?.
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="0.1"
android:fromYScale="1.0"
android:toYScale="1.0"
android:duration="100"
android:pivotX="100%"
>
</scale>
It sounds like you don't really want a scale animation, you want a resize animation instead. A scale animation will act like you are resizing an image. A resize animation should just affect the layout parameters of the view without altering the size of the contents (just the positioning).
You can do this in XML with a property animator:
https://developer.android.com/guide/topics/resources/animation-resource#Property
Alternatively, here is an example of a resize animation in code:
https://stackoverflow.com/a/8162779/342745

Scale bitmap keeping aspect ratio in layer-list

I'm trying to create a background drawable made of a gradient that fills the entire view and a pattern with left gravity that resizes to fit vertically while keeping its aspect ratio.
This is what I currently have:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/myGradient"/>
<item>
<bitmap android:src="#drawable/myPattern"
android:gravity="left" />
</item>
</layer-list>
Both drawables are VectorDrawables.
This is meant to be the background of a wrap_content height view.
This does not resize the pattern, but rather centers it vertically. If I set the gravity to fill_vertical, it only resizes in that axis and the aspect ratio breaks.
Is there any way to achieve this in XML without using ImageViews or other layouts? Can it be done programatically? Or do I require a different layout?

ImageView zoom animation cuts off image slightly

I am trying to implement zoom image functionality for images in the view. The view is kind of gallery view with images. I have applied the scale animation using xml and the animation works properly. The issue is when the image zooms the sides of image is cut off. I am using circularimageview as the image needs to be shown in a circle. I have tried increasing spacing between images but still the issue persists, the images gets cut off slightly when zoomed.
Can someone point out what may be the issue ?
The xml that I use for scale animation is
<scale
android:duration="300"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.15"
android:toYScale="1.15" >
</scale>
This was an issue with margins that was given around the image. I was able to resolve it by giving different margin values.

Android: How to only rotate the drawable part of an imageView?

I have an ImageView object where both its Background and drawable attributes are set.
I need to animate the drawable part of the ImageView while the background stay still.
I can't find a way to do it...
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:drawable="#drawable/ic_popup_sync_1"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200"
android:toDegrees="360" />
imageView.startAnimation(AnimationUtils.loadAnimation(context, animId));
Both the drawable and the background are rotating at the same time...
Set the background to a separate layout that sits behind the ImageView. Put both into a RelativeLayout where the background View is aligned to the ImageView by left, right, top, and bottom so that the background stays within the image's bounds. Then you can rotate the image freely.
EDIT:
Better yet, but the ImageView inside a layout and set the layout to WRAP_CONTENT. Set the layout's background to your background image.

Categories

Resources