gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:04:42 24 4
gpt4 key购买 nike

我目前在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com