Title: Scale Shape Drawable without stretching it with ObjectAnimator
Tags: android;animation;objectanimator
Question: I have an View that it's background is a Shape
The View:
<View
android:layout_width="wrap_content"
android:layout_height="74dp"
android:id="@+id/background_parent"
android:background="@drawable/item_background"&gt;
</View&gt;
The shape (Item background):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" &gt;
<corners
android:bottomLeftRadius="@dimen/corner_radius_in_rects"
android:bottomRightRadius="@dimen/corner_radius_in_rects"
android:topLeftRadius="@dimen/corner_radius_in_rects"
android:topRightRadius="@dimen/corner_radius_in_rects" /&gt;
<solid android:color="#f8f4fa" /&gt;
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" /&gt;
I'm trying to scale the view with ObjectAnimtor but it streches the view and the corners. I want it to be scaled and still keep the original shape properties (corners radius).
I tried:
scaleBackgroundView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
background.setBackground(getResources().getDrawable(R.drawable.item_background));
}
});
scaleBackgroundView.addListener(new Animator.AnimatorListener() {
...
@Override
public void onAnimationEnd(Animator animator) {
background.setBackground(getDrawable(R.drawable.item_background));
}
with no success. Anyone has an idea?
In other words,This is what it looks like:
I want round corners

Here is the accepted answer: Ok, so I found couple of solutions (more like workarounds).
The first one was to create a custom view and specify its own scale animation to only increase the gap between the corners and not to stretch then like before. The second solution (the one I used) is to split the the rectangle to three rectangles, Upper rect middle and bottom and to specify the middle one as a filler between the upper and the bottom. Then I set scale animation to the middle and translation animation to the bottom. Not the brightest idea but works fine.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:07/15/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><animation><objectanimator>', 'Title': 'Scale Shape Drawable without stretching it with ObjectAnimator', 'ViewCount': 575, 'id': 45116827, 'user_AboutMe': None, 'user_AccountId': 5499254.0, 'user_DisplayName': 'ben', 'user_Reputation': 1015.0, 'user_Views': 104.0, 'user_id': 4369107.0}}