我正在尝试在嵌套滚动视图中显示fab more按钮。我搜索了很多解决方案,但没有找到能够在右下角显示fab more按钮的解决方案
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="@+id/bt_close"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@android:color/white"
app:srcCompat="@drawable/ic_close" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Filter All Order"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:scrollingCache="true">
<LinearLayout
android:id="@+id/billBlock"
android:layout_width="match_parent"
android:layout_height="match_parent">
//many inner layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/grey_10" />
<android.support.v7.widget.RecyclerView
android:id="@+id/print_payment_list"
android:layout_margin="10dp"
android:background="@color/grey_20"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/fabFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_mic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_middle"
android:clickable="true"
android:tint="@color/grey_80"
app:backgroundTint="@color/grey_20"
app:fabSize="mini"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/ic_mic" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_middle"
android:clickable="true"
android:tint="@color/grey_80"
app:backgroundTint="@color/grey_20"
app:fabSize="mini"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/ic_photo_camera" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_smlarge"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginRight="@dimen/spacing_smlarge"
android:layout_marginTop="@dimen/spacing_middle"
android:clickable="true"
android:tint="@android:color/white"
app:fabSize="normal"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/ic_add" />
<!--android:src="@drawable/ic_close_black_24dp"-->
</FrameLayout>
</LinearLayout>
我在嵌套滚动视图.scroll的一个父级中有多个视图,并且一切正常。唯一的问题是fab不在右下位置
有人可以帮助我实现这一目标吗?由于是android的新手。
我需要像这样放置fab bar。这是Google的示例图片
答案 0 :(得分:1)
尝试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="@+id/bt_close"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@android:color/white"
app:srcCompat="@drawable/ic_close" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Filter All Order"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_below="@id/app"
android:layout_above="@+id/fabFrame"
android:layout_height="match_parent"
android:scrollbars="none"
android:scrollingCache="true">
<LinearLayout
android:id="@+id/billBlock"
android:layout_width="match_parent"
android:layout_height="match_parent">
//many inner layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/grey_10" />
<android.support.v7.widget.RecyclerView
android:id="@+id/print_payment_list"
android:layout_margin="10dp"
android:background="@color/grey_20"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<FrameLayout
android:id="@+id/fabFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="?attr/actionBarSize"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_mic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_middle"
android:clickable="true"
android:tint="@color/grey_80"
app:backgroundTint="@color/grey_20"
app:fabSize="mini"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/ic_mic" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_middle"
android:clickable="true"
android:tint="@color/grey_80"
app:backgroundTint="@color/grey_20"
app:fabSize="mini"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/ic_photo_camera" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_smlarge"
android:layout_marginLeft="@dimen/spacing_smlarge"
android:layout_marginRight="@dimen/spacing_smlarge"
android:layout_marginTop="@dimen/spacing_middle"
android:clickable="true"
android:tint="@android:color/white"
app:fabSize="normal"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/ic_add" />
<!--android:src="@drawable/ic_close_black_24dp"-->
</FrameLayout>
</RelativeLayout>
当要显示某些位置(例如右侧或底部)时,请始终使用线性布局获取连续视图,并使用Framelayout或Relative Layout。