绘制在垂直方向的LinearLayout中所有的按钮。添加属性
android:visibility="gone"
添加到单击主按钮时应出现的按钮。然后你就可以显示与行的主要按钮的OnClickListener这些按钮:
button.setVisibility(View.VISIBLE);
,其中按钮是参考代码布局。
Button button = (Button) findViewById (R.id.your_button_id);
编辑:
将动画添加到这个过程中,你要滑上/下出现的新的按钮和下面的按钮。 (将视图分组为布局,以便应用动画更加容易)。
这里有两个XML文件在您的RES /动画文件夹中创建:
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) {}
});
好吧,非常好,谢谢米格尔。最后一个问题:难以实现隐藏的按钮不会突然弹出,而是会滑落。我的意思是这样的,只是按钮:http:// www。webdesignerwall.com/demo/jquery/simple-slide-panel.html – enne87
我添加了动画的代码。我希望它有帮助。 –
非常好,谢谢你的帮助miguel :) – enne87