Android CoordinatorLayout 隐藏/覆盖主视图

标签 android android-xml android-coordinatorlayout floating-action-button

我在内部使用 CoordinatorLayout 和 ViewPager。问题是,列表的第一个条目(在 ViewPager 的第一页中)被选项卡隐藏了。当我使用 LinearLayout 而不是 CoordinatorLayout 时,一切正常。

  1. 如何解决重叠问题?
  2. 应该在此处还是在 ListView XML 中添加 FloatingButton?

MainActivity

这是 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"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

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

    <android.support.v4.view.ViewPager
            android:id="@+id/pager_list_views"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </android.support.v4.view.ViewPager>

    <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@android:drawable/ic_menu_add"
            app:layout_anchor="@id/pager_list_views"
            app:layout_anchorGravity="bottom|right|end" />

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

最佳答案

将此添加到 ViewPager

  app:layout_behavior="@string/appbar_scrolling_view_behavior"

如果您使用 CoordinatorLayout,您必须指定一个行为,如果您控制设计的这些方面会更安全。

关于Android CoordinatorLayout 隐藏/覆盖主视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31334891/

相关文章:

java - 将从安卓设备接收到的数据输出为声音

java - SuggestionListener 中的 onSuggestionClick(intposition) 给出 ArrayList 的绝对位置

java - 安装 Android ADT 14 : "R cannot be resolved" 后

java - 安卓工作室 : Can't find the emulator executable

android - 我的布局文件中的红色感叹号是什么意思?

android - 将 LinearLayout 置于屏幕中心,用 ImageView 填充上面的空间

java - Android 选项卡式 Activity 底部关闭屏幕

android - 从自定义首选项获取 View

android - 使用 AppBarLayout 的 CoordinatorLayout 自定义行为

android - CoordinatorLayout 内的 ViewPager 中的非滚动 fragment