我想做一个FAB,在点击后打开剩下的2个其他FAB。但它并没有开始隐形。我在那些代码行中使用了所有方法,但它不起作用。 (ScaleX-Y = 0, android:invisibility, setInvisibility etc..)
DersActivity.java
private Boolean isFabOpen = false;
private FloatingActionButton fab_ders, fab_ders_ara, fab_ders_ekle;
private Animation fab_open, fab_close, rotate_forward, rotate_backward;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
...
fab_ders = (FloatingActionButton) findViewById(R.id.fab_ders);
fab_ders_ara = (FloatingActionButton) findViewById(R.id.fab_ders_ara);
fab_ders_ekle = (FloatingActionButton) findViewById(R.id.fab_ders_ekle);
fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open_ders);
fab_close = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_close_ders);
rotate_forward = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_forward);
rotate_backward = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_backward);
fab_ders.setOnClickListener(this);
fab_ders_ara.setOnClickListener(this);
fab_ders_ekle.setOnClickListener(this);
...
...
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.fab_ders:
animateFAB();
break;
case R.id.fab_ders_ara:
Log.d("Test", "Fab 1");
break;
case R.id.fab_ders_ekle:
Log.d("Test", "Fab 2");
break;
}
}
public void animateFAB() {
if (isFabOpen) {
fab_ders.startAnimation(rotate_backward);
fab_ders_ara.startAnimation(fab_close);
fab_ders_ekle.startAnimation(fab_close);
fab_ders_ara.setClickable(false);
fab_ders_ekle.setClickable(false);
isFabOpen = false;
Log.d("Test", "close");
} else {
fab_ders.startAnimation(rotate_forward);
fab_ders_ara.startAnimation(fab_open);
fab_ders_ekle.startAnimation(fab_open);
fab_ders_ara.setClickable(true);
fab_ders_ekle.setClickable(true);
isFabOpen = true;
Log.d("Test", "open");
}
}
我在此文件中使用Animation
但问题并不重要。
activity_ders.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".DersActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:elevation="5dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:elevation="5dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<include layout="@layout/tool_bar2"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_ders"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_ders_ekle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/fab2_margin"
android:src="@drawable/ic_add_circle_white_24dp"
android:visibility="gone"
app:backgroundTint="@color/colorFAB2"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:fabSize="mini"
android:scaleX="0.0"
android:scaleY="0.0"
android:alpha="0.0"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_ders_ara"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/fab1_margin"
android:src="@drawable/ic_search_white_24dp"
android:visibility="gone"
app:backgroundTint="@color/colorFAB2"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:fabSize="mini"
android:scaleX="0.0"
android:scaleY="0.0"
android:alpha="0.0"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_ders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add"
app:backgroundTint="@color/colorFAB2"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
<include layout="@layout/nav_view"/>
</android.support.v4.widget.DrawerLayout>
这就是我试图在视觉上实现的目标: