0

我对为 android 开发应用程序非常陌生。现在我想做的是实现四个按钮,一旦用户点击,比如说,在最上面的按钮上,另外两个子按钮应该出现在点击的按钮下方,另外三个剩余的按钮应该自动向下移动。

我认为我的解释不是百分百清楚,所以我尝试用一​​些图像来说明问题。

现在是四个按钮:

http://advancedata.ad.funpic.de/First-AGApp.png


一旦用户按下按钮一,就会出现两个额外的按钮,另外三个按钮应该向下移动:

http://advancedata.ad.funpic.de/Second-AgApp.png
我会非常感谢任何建议如何实现这一点。

谢谢,恩

4

1 回答 1

1

在具有垂直方向的 LinearLayout 中绘制所有按钮。添加属性

android:visibility="gone"

单击主按钮时应出现的按钮。然后你可以在主按钮的 OnClickListener 中显示这些按钮:

button.setVisibility(View.VISIBLE);

其中 button 是对代码中布局的引用。

Button button = (Button) findViewById (R.id.your_button_id);

编辑:

要将动画添加到流程中,您必须向上/向下滑动出现的新按钮和下面的按钮。(将视图分组到布局中,以便更轻松地应用动画)。

这里有两个 XML 文件要在 res/anim 文件夹中创建:

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) {}

});
于 2012-06-07T11:13:53.377 回答