安卓比例子父高度未更改

  • 本文关键字:高度 android xml
  • 更新时间 :
  • 英文 :


我有一个ImageViewRelativeLayout父级,这是 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 ***/

现在图像视图大小已更改,但其父级大小仍然相同

使用此布局

<?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();
}
}

最新更新