在不使用 ObjectAnimator 拉伸的情况下缩放 Shape Drawable
Scale Shape Drawable without stretching it with ObjectAnimator
我有一个 View
它的背景是 Shape
观点:
<View
android:layout_width="wrap_content"
android:layout_height="74dp"
android:id="@+id/background_parent"
android:background="@drawable/item_background">
</View>
shape
(项目背景):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<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" />
<solid android:color="#f8f4fa" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
我正在尝试使用 ObjectAnimtor
缩放视图,但它拉伸了视图和角落。我希望它被缩放并仍然保持原始形状属性(角半径)。
我试过了:
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));
}
没有成功。有人有想法吗?
换句话说,这就是它的样子:
我要圆角
好的,所以我找到了几个解决方案(更像是解决方法)。
第一个是创建一个自定义视图并指定其自己的缩放动画以仅增加角之间的间隙而不是像以前那样拉伸。第二种解决方案(我使用的那个)是将矩形拆分为三个矩形,Upper rect middle 和 bottom 并将中间的指定为 upper 和 bottom 之间的填充物。然后我将缩放动画设置在中间,平移动画设置在底部。不是最聪明的主意,但效果很好。
我有一个 View
它的背景是 Shape
观点:
<View
android:layout_width="wrap_content"
android:layout_height="74dp"
android:id="@+id/background_parent"
android:background="@drawable/item_background">
</View>
shape
(项目背景):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<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" />
<solid android:color="#f8f4fa" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
我正在尝试使用 ObjectAnimtor
缩放视图,但它拉伸了视图和角落。我希望它被缩放并仍然保持原始形状属性(角半径)。
我试过了:
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));
}
没有成功。有人有想法吗?
换句话说,这就是它的样子:
我要圆角
好的,所以我找到了几个解决方案(更像是解决方法)。 第一个是创建一个自定义视图并指定其自己的缩放动画以仅增加角之间的间隙而不是像以前那样拉伸。第二种解决方案(我使用的那个)是将矩形拆分为三个矩形,Upper rect middle 和 bottom 并将中间的指定为 upper 和 bottom 之间的填充物。然后我将缩放动画设置在中间,平移动画设置在底部。不是最聪明的主意,但效果很好。