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排成一行,所以我决定做个例外。 –