Android 材料晶圆变形
根据需要,浮动动作按钮可以变形为动作菜单,如。是否有任何方法仅使用材料库(不使用第三方LIB)执行此操作 我尝试了库,但它打破了工厂的立场,根据底部的应用程序栏后,菜单关闭 这是我得到的结果 守则: activity_main.xmlAndroid 材料晶圆变形,android,material-design,floating-action-button,Android,Material Design,Floating Action Button,根据需要,浮动动作按钮可以变形为动作菜单,如。是否有任何方法仅使用材料库(不使用第三方LIB)执行此操作 我尝试了库,但它打破了工厂的立场,根据底部的应用程序栏后,菜单关闭 这是我得到的结果 守则: activity_main.xml <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://sche
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways|snap"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fabAlignmentMode="end"
app:backgroundTint="?colorPrimary"
android:layout_gravity="bottom">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:useCompatPadding="true"
app:layout_anchor="@id/bottomBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fab"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#53000000"
android:visibility="invisible"
android:id="@+id/overlay"/>
<io.codetail.widget.RevealFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.files.view.MenuCardView
android:id="@+id/menu"
android:visibility="invisible"
android:layout_margin="56dp"
android:layout_gravity="bottom|end"
android:layout_width="wrap_content"
app:cardUseCompatPadding="true"
app:menu="@menu/new_tab_options"
android:layout_height="wrap_content"/>
</io.codetail.widget.RevealFrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
刚刚找到一个解决方案:
使用
com.google.android.material.transformation.FabTransformationSheetBehavior
进行图纸布局,使用com.google.android.material.transformation.FabTransformationScrimBehavior
进行叠加视图。要支持漂亮的动画,请使用com.google.android.material.transformation.TransformationChildCard
或com.google.android.material.transformation.TransformationChildLayout
查看工作表的根视图。要将fab转换为图纸集isExpanded
到fab到true
并将其向后设置isExpanded
到false我发现了这个官方网站-上面的代码不推荐使用:
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.konifar.fab_transformation.FabTransformation
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
overlay.setOnClickListener {
FabTransformation.with(fab)
.setOverlay(it)
.transformFrom(menu)
}
fab.setOnClickListener {
FabTransformation.with(it)
.setOverlay(overlay)
.transformTo(menu)
}
}
override fun onBackPressed() {
if(menu.visibility== View.VISIBLE){
FabTransformation.with(fab)
.setOverlay(overlay)
.transformFrom(menu)
}else super.onBackPressed()
}
}