2016-12-06 6 views
0

私はビューを垂直にセンタリングしています。 layout_centerHorizontal属性を削除してビューの一番上に上げたいと思っていますが、その遷移をアニメーション化したいと思います。layout_centerHorizo​​ntalの除去をアニメ化する

の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... 
} 
+0

マージンに 'sp'を使用しないでください。 –

+0

haha​​、通常はそうではありません。しかし、私は余白にTextViewを一番上に固定して並べ替えたいので、例外を作ることにしました。 –

答えて

0

アニメーションコード:Javaのファンクションコードで

<?xml version="1.0" encoding="utf-8"?> 
<set 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator" 
android:fillAfter="true"> 

<translate 
android:fromYDelta="0%p" 
android:toYDelta="100%p" 
android:duration="800" /> 
</set> 

private void showSplits(){ 
centerBox.startAnimation(animFadein); 
} 
OnCreate{ 
// load the animation 
animMoveIn = AnimationUtils.loadAnimation(getApplicationContext(), 
R.anim.animate); 
animMoveIn.setAnimationListener(this); 
} 

をそして、あなたはAnimationListenerを実装する必要があります:では、コードの表示を作成します。

関連する問題