android规模子父级高度未更改

时间:2017-07-10 12:44:17

标签: 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 ***/

现在ImageView大小已更改,但其父级仍为相同大小

1 个答案:

答案 0 :(得分:0)

使用此布局

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

    }
}