我正在尝试使用android中的动画来调整我的布局。问题是布局开始从两个方向缩小。我只是希望它从底部减少。我尝试设置枢轴,但它不起作用。
layout.setPivotY(0f);
layout.setPivotX(0f);
ValueAnimator va = ValueAnimator.ofInt(mFragmentheight, mFragmentheight/2);
va.setDuration(400);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
layout.getLayoutParams().height = value.intValue();
layout.requestLayout();
}
});
va.start();
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cancel"
android:layout_alignParentTop="true"
android:clickable="true"
android:layout_alignParentRight="true"
android:padding="5dp"/>
<TextView
android:id="@+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="83dp"
android:layout_above="@+id/confirm"
android:text="Are you sure you want to exit"
android:paddingBottom="10dp"
android:textSize="20sp"
/>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/img"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img"
android:layout_marginBottom="83dp"
android:orientation="horizontal">
<Button
android:id="@+id/exitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/exit"
android:textAllCaps="true"
android:textSize="16.0sp"
/>
<Button
android:id="@+id/closeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="@string/cancel"
android:textAllCaps="true"
android:textSize="14.0sp"
/>
</LinearLayout>
</RelativeLayout>
</merge>