あわと申します。
AnimationとVisivilityの組み合わせの動作でちょっと悩んでいます。
良い解決方法ないでしょうか?
◇やりたいこと
Button01を押下することでButton01の背後(Z order behind)からButton02をAnimationを利用して下方向
にtranslateしたい。
◇問題
下記の実験コードを作って動作させると、概ね期待通りの動作をするのですが、
button02がVISIBLEになってからAnimationされるため、
一瞬Button01の下にButton02がチラッと表示されしまいます。
この「チラッ」が見えないようにしたいと思っています。
Visibilityを制御しているのは、画面表示時にはbutton02は見えない状態にしておき、
button01が押下された場合のみbutton02を表示したいと考えているためです。
◇実験コード
layout.xml
RelativeLayout内に下記の2つのViewを配置。
----
<!-- 前面に表示されているボタン -->
<Button
android:id="@+id/Button01"
android:text="Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<!-- 下にスライドするボタン(初期状態はGONE) -->
<Button
android:id="@+id/Button02"
android:text="Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/Button01"
android:visibility="gone"
/>
----
Activity側実装
----
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
button01 = (Button)findViewById(R.id.Button01);
button02 = (Button)findViewById(R.id.Button02);
button01.setOnClickListener(this);
// Control Z order
button01.bringToFront();
}
@Override
public void onClick(View v) {
if ( v == button01 )
{
// btn1クリックで下にスライドするアニメーション開始
button02.startAnimation(anim);
button02.setVisibility(View.VISIBLE);
}
}
----
translate定義
----
<set xmlns:android="
http://schemas.android.com/apk/res/android"
android:fillBefore="false"
android:fillAfter="false" >
<translate
android:interpolator="@android:anim/accelerate_interpolator"
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="-100%"
android:toYDelta="0"
android:duration="1000"
android:fillBefore="false"
android:fillAfter="false"
/>
</set>
----