Android: 如何在滑动视图中制作静态元素?

Android: How to make static elements in Swipe Views?

我正在开发一个应用程序,我想在一开始就介绍一下如何使用它。我正在将 ViewPager 与 fragemts 一起使用。一切正常,但我怎样才能制作一些元素,例如按钮或徽标静态?我希望它们是永久的,只有背景和一些其他元素可以在滑动时移动或更改。

如果您希望它们是静态的,则它们不能成为 ViewPager 内的 Fragments 的一部分。您可以使用 RelativeLayout 将它们放在 ViewPager 的上方或下方,或者您可以使用 FrameLayout.

将它们放在顶部

ViewPager

下方的静态内容示例

fragment_pager.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_width="match_parent" >

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

    <TextView
        android:id="@+id/static_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/container" />

</RelativeLayout>