我有一个带有RelativeLayout
父元素的ImageView
,这个是xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageViwe
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/love"
android:src="@drawable/love_large"
android:layout_alignParentRight="true" />
</RelativeLayout >
现在,在jave中,我扩展了ImageView
private ImageView love;
love = (ImageView)findViewById(R.id.love);
/*** animation scale with e value ***/
love.setScaleX(e);
love.setScaleY(e);
/*** animation scale ***/
现在,ImageView大小发生了变化,但其父对象的大小仍然不变
发布于 2017-07-10 13:19:54
使用此布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/love"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_love" />
</RelativeLayout>
和
public class MainActivity extends AppCompatActivity {
ImageView love;
RelativeLayout root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
love = (ImageView)findViewById(R.id.love);
root = (RelativeLayout)findViewById(R.id.root);
ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.0f,5.0f);
valueAnimator.setDuration(5000);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value =(Float) animation.getAnimatedValue();
love.setScaleX(value);
love.setScaleY(value);
}
});
valueAnimator.start();
}
}
https://stackoverflow.com/questions/45012430
复制