我没有使用锚,它应该工作。 通常,可见性消失了(由XML设置)。当我按下按钮时,它变得可见(直到这里,工作)。然后,当我按下另一个按钮时,它应该消失,但没有任何反应。 减少XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/tbTela3"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ToolBar"
app:titleTextColor="#757575"
app:subtitleTextColor="#757575" />
<android.support.design.widget.CoordinatorLayout
android:id="@+id/cLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tbTela3">
<ScrollView>
[...]
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:elevation="8dp"
android:src="@drawable/replay"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
减少主要活动:
public void ZoomIn() {
[...]
zoomIn.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation anim) {}
public void onAnimationRepeat(Animation anim) {}
public void onAnimationEnd(Animation anim) {
fab.setVisibility(View.VISIBLE); // WORKS FINE
}
});
fab.startAnimation(zoomIn);
}
[...]
public void Clear() {
[...]
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
readX.requestFocus();
cardII.setVisibility(View.GONE); // WORKS FINE TOO
fab.setVisibility(View.GONE); // BUT THIS DON'T
fadeOut.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation anim) {}
public void onAnimationRepeat(Animation anim) {}
public void onAnimationEnd(Animation anim) {
clear.setVisibility(View.INVISIBLE);
}
});
clear.startAnimation(fadeOut);
}
});
anim.start();
}
fab.setVisibility(View.GONE)不能独立于它所处的位置Clear ...我将代码简化为更易读,希望这不是问题。
答案 0 :(得分:1)
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(View.NO_ID);
fab.setLayoutParams(p);
fab.setVisibility(View.GONE);
或尝试
fab.show(); //show
fab.hide(); //hide
答案 1 :(得分:0)
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(View.NO_ID);
fab.setLayoutParams(p);
fab.setVisibility(View.invisible);
不要使用GONE
不可见:
此视图不可见,但仍会占用布局空间。
GONE:
此视图不可见,并且不会占用任何空间进行布局。
不可见:
Adapter的getView()函数名为
GONE:
适配器的getView()函数没有调用,因此在不需要时阻止视图加载
答案 2 :(得分:0)
现在一切正常。最终代码:
public void ZoomIn() {
[...]
fab.show();
}
我删除了所有内容并放入fab.show()
public void Clear() {
[...]
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
readX.requestFocus();
cardII.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation anim) {}
public void onAnimationRepeat(Animation anim) {}
public void onAnimationEnd(Animation anim) {
clear.setVisibility(View.INVISIBLE);
}
});
clear.startAnimation(fadeOut);
}
});
anim.start();
}