如何以编程方式更改fabGravity

时间:2019-07-12 07:10:59

标签: android floating-action-button floating-action-menu-listener fab-speed-dial

我有使用[strong>快速拨号库的浮动操作按钮。在此,我想通过编程方式更改 fabGravity 。我该如何实现?

<io.github.yavski.fabspeeddial.FabSpeedDial
            android:id="@+id/position_bottom_end"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            app:fabGravity="bottom_start"
            app:fabMenu="@menu/menu_main"
            app:touchGuard="false" />

1 个答案:

答案 0 :(得分:0)

尝试

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    FrameLayout.LayoutParams layoutparams = (FrameLayout.LayoutParams)
            fab.getLayoutParams();
    layoutparams.gravity = Gravity.BOTTOM | GravityCompat.START;
    fab.setLayoutParams(layoutparams);