先写两个按钮,点击一个,布局下滑隐藏,点击另一个,上滑显示
点击按钮,浅绿色的部分隐藏或显示

Button btn = findViewById(R.id.button);
Button upBtn = findViewById(R.id.up_button);
final LinearLayout ll = findViewById(R.id.ll);
// 点击隐藏
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ll.animate().translationY(830)
.alpha(0.0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
ll.setVisibility(View.GONE);
}

这篇博客介绍了如何在Android中实现通过手指下滑隐藏布局,点击按钮则元素上滑显示的功能。首先,创建两个按钮分别对应布局的隐藏和显示。然后,通过监听手势,重写onFling方法来实现布局的滑动效果。最后,讨论了增强版实现,即布局原本不存在,点击按钮时布局元素才会弹出,再次点击则隐藏。
最低0.47元/天 解锁文章
168

被折叠的 条评论
为什么被折叠?



