android - ListView 上方 ViewPager 中的 float 操作按钮

标签 android android-layout listview

我目前在 LinearLayout 中有一个可用的 float 操作按钮。它所在的 LinearLayout 位于 SlidingTabLayout 的一个选项卡中。我希望 float 操作按钮位于第一个选项卡内 ListView 的顶部,并且还显示在第二个选项卡内的相同位置。

所以这是 activity_main.xml,其中底部的 FrameLayout 用于 float 操作按钮:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <com.stephenprotzman.o.SlidingTabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        android:elevation="2dp" />

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



    </android.support.v4.view.ViewPager>

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp" />
</LinearLayout>

如果有帮助,这里是声明实际 float 操作按钮的 fab_layout.xml

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.stephenprotzman.o.FloatingActionButton
        android:id="@+id/fab_1"
        android:layout_width="@dimen/fab_size"
        android:layout_height="@dimen/fab_size"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:background="@drawable/fab_background"
        android:elevation="@dimen/fab_elevation"
        android:stateListAnimator="@animator/fab_anim">

        <ImageView
            android:layout_width="@dimen/fab_icon_size"
            android:layout_height="@dimen/fab_icon_size"
            android:layout_gravity="center"
            android:duplicateParentState="true"
            android:src="@drawable/fab_icons" />

    </com.stephenprotzman.o.FloatingActionButton>


</FrameLayout>

我目前布置 float 操作按钮的方式是在其自己的 LinearLayout 部分内,因此 ListView 在到达按钮时就停止了。这样做的好处是它确实显示在 SlidingTabLayout 的两个选项卡上,但仍在其自己的部分内。

在理想情况下,我希望按钮位于指定位置(距离底部和右侧 16 dp),但在第一个选项卡的 ListView 顶部,第二个选项卡内部有 map ,所以我也希望它也位于其之上。

最佳答案

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <include
                android:id="@+id/tool_bar"
                layout="@layout/tool_bar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <com.stephenprotzman.o.SlidingTabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/primary"
                android:elevation="2dp" />

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

        </LinearLayout>

        <include
            android:id="@+id/fab_layout"
            layout="@layout/fab_layout"
            android:layout_width="@dimen/fab_size"
            android:layout_height="@dimen/fab_size"
            android:layout_marginBottom="16dp"
            android:layout_marginRight="16dp" 
            layout_gravity="bottom|right"/>
    </FrameLayout>

关于android - ListView 上方 ViewPager 中的 float 操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30872371/

相关文章:

java - 获取值并将其显示在 EditText 上

android - 自定义 Alertdialog 宽度大于布局 xml 中显示的宽度

android - 是否可以在 View 上设置背景 png 并将其锚定到顶部而不在 Android 中缩放?

android - 如何区分16 :9 display from a 18:9 one?

javascript - polymer 1.0 ListView 元素的示例?

android - ListView onItemClick 区域在手机和平​​板电脑上不同

android - String.find 不适用于 '.'(点)字符 : corona SDK

android - 如何从 Phonegap 打开 Google Play 商店

android - 封闭式或圆形 Horizo​​ntal ListView Android

android - ListView 中的 setOnItemClickListener VS setOnItemSelectedListener。