[英]fixed position floating action button like gmail android
I have a scrollview with three view pagers inside a fragment container.I want to place a fixed floating action button like gmail inbox at the bottom right of the page and not in bottom right of the scrollview.It should be fixed whether I scroll or not.I am posting my drawer layout xml file.please help me 我有一个在片段容器内有三个视图分页器的滚动视图。我想在页面的右下方而不是在滚动视图的右下方放置一个固定的浮动操作按钮,例如gmail inbox,无论是否滚动,都应该固定我正在发布我的抽屉布局xml文件。请帮助我
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.efflorescence.settingneeds.HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1sp"
android:background="@android:color/white"/>
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<!--fragment container-->
<FrameLayout
android:id="@+id/container"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<!--Home Page Content put here-->
<ScrollView
android:id="@+id/svcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:background="@android:color/white"
android:layout_marginTop="0dp">
<RelativeLayout
android:id="@+id/home_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/pro_req_heading"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#2094c5"
android:textColor="@android:color/white"
android:gravity="center"
android:text="[ IMMEDIATE REQUIREMENT ]"/>
<RelativeLayout
android:id="@+id/product_req_container"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@+id/pro_req_heading"
android:layout_marginBottom="1dp">
<android.support.v4.view.ViewPager
android:id="@+id/pager1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"/>
</RelativeLayout>
<TextView
android:id="@+id/pro_review_heading"
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_below="@+id/product_req_container"
android:layout_height="50dp"
android:background="#2094c5"
android:textColor="@android:color/white"
android:gravity="center"
android:text="[ MOST REVIEW PRODUCTS ]"/>
<RelativeLayout
android:id="@+id/product_review_container"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@+id/pro_review_heading">
<android.support.v4.view.ViewPager
android:id="@+id/pager2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
<TextView
android:id="@+id/pro_sale_heading"
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_below="@+id/product_review_container"
android:layout_height="50dp"
android:background="#2094c5"
android:textColor="@android:color/white"
android:gravity="center"
android:text="[ MOST SALE PRODUCTS ]"/>
<RelativeLayout
android:id="@+id/product_sale_container"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/pro_sale_heading">
<android.support.v4.view.ViewPager
android:id="@+id/pager3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
<fragment
android:id="@+id/nav_drwr_fragment"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:name="com.example.efflorescence.settingneeds.navigation.NavigationFragment"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation"/>
You need to use CoordinatorLayout
您需要使用
CoordinatorLayout
main.xml main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.c217.reddyteacherapp.baseActivity">
<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>
<include layout="@layout/content_base" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
and put all your other component in content_base xml file 并将所有其他组件放在content_base xml文件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.