gpt4 book ai didi

Android:我们如何在 xml 布局中隐藏/显示 float 操作按钮(fab)

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:56 25 4
gpt4 key购买 nike

我的 Activity 中有一个 float 操作按钮。我可以使用以下代码以编程方式显示/隐藏 fab 按钮:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.show()
fab.hide()

但我无法在 xml 布局中设置这些属性。我找不到任何东西来设置它在 xml 中默认隐藏。这是我的 xml 布局。

    <android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
app:layout_anchor="@id/list_view"
app:layout_anchorGravity="bottom|right|end" />

更新:我不想将我的 fab 按钮可见性设置为 GONE。我想在 XML 布局中设置 hide()。我想在延迟后在我的 Activity 中调用 fab 上的 show() 。

最佳答案

在“FloatingActionButtonLollipop.java”和“FloatingActionButtonEclairMr1.java”中,show() 首先检查其可见性,然后播放动画。

if (mView.getVisibility() != View.VISIBLE || mIsHiding) {
// If the view is not visible, or is visible and currently being hidden, run
// the show animation
mView.clearAnimation();
mView.setVisibility(View.VISIBLE);
Animation anim = android.view.animation.AnimationUtils.loadAnimation(
mView.getContext(), R.anim.design_fab_in);
anim.setDuration(SHOW_HIDE_ANIM_DURATION);
anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
anim.setAnimationListener(new AnimationListenerAdapter() {
@Override
public void onAnimationEnd(Animation animation) {
if (listener != null) {
listener.onShown();
}
}
});
mView.startAnimation(anim);
}

我认为您可以简单地将可见性设置为消失。

关于Android:我们如何在 xml 布局中隐藏/显示 float 操作按钮(fab),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34350521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com