【问题标题】:Android Overlapping views and handle clicksAndroid 重叠视图和处理点击
【发布时间】:2016-01-17 13:58:08
【问题描述】:

所以我有这个活动布局:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
            <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>
    </android.support.design.widget.CoordinatorLayout>

    <FrameLayout
        android:id="@+id/mainContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

我的mainContent 是片段将放大其视图的地方。在我的特殊情况下,膨胀的片段将具有 cardviews 的 recyclerview。

问题是,布局看起来像我想要的那样,像这样:

但导航抽屉图标不可点击。如果我用框架布局交换协调器布局,就会发生这种情况:

导航抽屉变得可点击,但图标被切断。我知道我在这里遗漏了一些东西,我只是想不通。 我试图将两者都放在一个框架布局中,但输出相同。

【问题讨论】:

  • 能否添加您的活动 java 代码?

标签: android overlapping android-coordinatorlayout floating-action-button


【解决方案1】:

那个按钮不应该在那里。这不是MaterialDesign Guidelines 所说的。

您可以将 FloatingActionaButton 与以下样式一起使用: https://github.com/xuyisheng/DesignSupportLibraryDemo

或者像下面这样使用它:

<android.support.design.widget.FloatingActionButton
    android:onClick="checkin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:clickable="true"
    android:src="@drawable/ic_discuss"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|right|end"/>

https://github.com/xuyisheng/DesignSupportLibraryDemo/blob/master/app/src/main/res/layout/activity_detail.xml

关于那个FrameLayout,正如我所见,你有CoordinatorLayout 和那个FrameLayout 我认为FrameLayout 我们识别像NavigationDrawer

尝试在其他地方使用它。或使用以下答案: https://stackoverflow.com/a/32035783/4409113

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多