0
我有一個垂直居中的視圖。我想要刪除layout_centerHorizontal
屬性,以便它會上升到視圖的頂部,但我想爲該過渡製作動畫。動畫布局_中心水平的移除
XML:
<RelativeLayout
android:id="@+id/center_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="65sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:animateLayoutChanges="true"
>
...
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="HELLO WORLD"
android:textColor="#fff"
android:maxLines="1"
android:gravity="center"
android:layout_centerVertical="true"
android:textSize="35sp" />
...
</RelativeLayout>
的Java
private void showSplits(){
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) centerBox.getLayoutParams();
lp.removeRule(RelativeLayout.CENTER_VERTICAL);
centerBox.setLayoutParams(lp);
//but I want to animate this instead...
}
不要使用'sp'作爲保證金:) –
哈哈,通常我不會。但是,我希望邊緣與固定在頂端的TextView排成一行,所以我決定做個例外。 –