すべてのボタンを垂直方向のLinearLayoutで描画します。属性を追加します
android:visibility="gone"
メインボタンをクリックしたときに表示されるボタンに移動します。次に、これらのボタンをメインボタンのOnClickListenerに次の行で表示できます。
button.setVisibility(View.VISIBLE);
ここで、buttonは、コード内のレイアウトへの参照です。
Button button = (Button) findViewById (R.id.your_button_id);
編集:
プロセスにアニメーションを追加するには、表示される新しいボタンと下のボタンを上下にスライドさせる必要があります。(ビューをレイアウトにグループ化して、アニメーションを適用しやすくします)。
ここに、res/animフォルダーに作成する2つのXMLファイルがあります。
slide_down.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="-50" android:toYDelta="0"
android:duration="300" />
slide_up.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0" android:toYDelta="-50"
android:duration="300" />
次のコードを使用して、コードにアニメーションを作成します。
Animation slideDown = AnimationUtils.loadAnimation(this, R.anim.slide_down);
そしてそれをボタンに適用します:
secondaryButton.startAnimation(slideDown);
上にスライドするときは、アニメーションの終了前ではなく、終了後に可視性を「終了」に設定する必要があります。これを行うには、アニメーションリスナーを設定し、onAnimationEndのボタンを非表示にする必要があります。
slideUp.setAnimationListener(new AnimationListener () {
@Override
public void onAnimationEnd(Animation animation) {
secondaryButton.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});