Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式更改clans fab菜单方向_Android_Kotlin_Orientation_Floating Action Button_Onconfigurationchanged - Fatal编程技术网

Android 以编程方式更改clans fab菜单方向

Android 以编程方式更改clans fab菜单方向,android,kotlin,orientation,floating-action-button,onconfigurationchanged,Android,Kotlin,Orientation,Floating Action Button,Onconfigurationchanged,我正在使用创建一个带有一组按钮的菜单 我的菜单是一个开放方向,设置为“向上”,如果手机处于portait模式,这个功能非常好。然而,如果我把它转到横向模式,一半的按钮会被裁剪 我想知道是否可以在onConfigurationChanged方法上以编程方式更改fab菜单打开方向 大概是这样的: override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newCon

我正在使用创建一个带有一组按钮的菜单

我的菜单是一个开放方向,设置为“向上”,如果手机处于portait模式,这个功能非常好。然而,如果我把它转到横向模式,一半的按钮会被裁剪

我想知道是否可以在onConfigurationChanged方法上以编程方式更改fab菜单打开方向

大概是这样的:

override fun onConfigurationChanged(newConfig: Configuration) {
    super.onConfigurationChanged(newConfig)
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        // set menu fab orientation to start|left
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        // set menu fab orientation to up
    }
}

我似乎找不到以编程方式更改此项的方法。有人知道怎么做吗?

不幸的是,浮动操作菜单目前只支持向上和向下打开方向

上下展开菜单的选项

目前还没有以编程方式更改配置方向的选项:它是在XML中设置的

添加水平布局按钮的选项需要对库进行重大更改,因为测量和布局例程未设置为处理这种情况

推荐 如果在水平显示菜单时,标签将从上到下排列,您的用户体验将受到负面影响。此外,大量的菜单项在某种程度上击败了晶圆厂的竞争优势

浮动操作按钮表示应用程序中的主要操作。浮动操作按钮用于提升的操作

考虑到所有这些,我强烈建议您重新考虑您的方法,并限制要添加到FAB菜单中的项目数量,以便这些项目适合两个方向。将不适合选项菜单或位置合适的上下文弹出菜单的项目移动

作为旁注,家族回购协议是生命的终结。我不知道谁会接管它,但它目前的状况是一个风险

处理配置更改 一种情况是,repo不允许基于配置进行编程更改,但有一种方法可以解决这一问题:使用基于配置的片段来实现相同的结果。例如:

res/layout/activity_main.xml

这两个文件之间的唯一区别是我们需要根据配置更改布局

现在,我们添加了一种魔力,将所有这些都整合在一起。两个文件让Android知道选择哪个文件

/res/values/layouts.xml


@布局图/碎片制作图
/res/values/layouts-land.xml


@布局/碎片制作景观
有关更多信息,请参阅

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.fabmenu.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main"/>

    <!-- Replace the FAB with a fragment reference -->
    <include layout="@layout/fragment_fab_menu"/>

</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<com.github.clans.fab.FloatingActionMenu
    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"
    ...    
    app:menu_openDirection="left"
    >

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/menu_item_horse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/fab_add"
        app:fab_colorNormal="@color/colorAccent"
        app:fab_label="Horse"
        app:fab_size="mini"/>

    ...

</com.github.clans.fab.FloatingActionMenu>
<?xml version="1.0" encoding="utf-8"?>
<com.github.clans.fab.FloatingActionMenu
    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"
    ...    
    app:menu_openDirection="left"
    >

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/menu_item_horse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/fab_add"
        app:fab_colorNormal="@color/colorAccent"
        app:fab_label="Horse"
        app:fab_size="mini"/>

    ...

</com.github.clans.fab.FloatingActionMenu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="fragment_fab_menu" type="layout">@layout/fragment_fab_portrait</item>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Here name refers to the id we gave it in activity_main.xml -->
    <item name="fragment_fab_menu" type="layout">@layout/fragment_fab_landscape</item>
</resources>