浮动操作按钮没有显示的片段里​​面全 [英] Floating Action Button not showing fully inside a fragment

本文介绍了浮动操作按钮没有显示的片段里​​面全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个片段使用FAB按钮以及RecyclerView。这个片段是一个TabViewPager的一个实例。我有与FAB按钮的问题。我已经放在RecyclerView和里面的FrameLayout,其中FAB按钮移到位于右下角的晶圆厂按钮。现在,我面临的问题是FAB按钮没有完全可见。其部分的一半已被隐藏显示在下面的屏幕截图。任何一个可以帮助我解决这个问题。提前致谢。

注意:的FAB是正确对准一旦滚动。问题出现了,只有当它是理想的(滚动完成之前)。

fragment.xml之

 < XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
             的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent>

    < android.support.v7.widget.RecyclerView
        机器人:ID =@ + ID / recyclerView
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>

    < android.support.design.widget.FloatingActionButton
        机器人:ID =@ + ID /晶圆厂
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =结束|底
        机器人:layout_margin =10dp
        应用程序:backgroundTint =@色/红
        机器人:SRC =@可绘制/ ic_done/>
< /的FrameLayout>
 

tabviewpagerlayout.xml

 < XML版本=1.0编码=UTF-8&GT?;
< android.support.design.widget.CoordinatorLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID / main_content
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>


    < android.support.design.widget.AppBarLayout
        机器人:ID =@ + ID / appBarLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar>


        < android.support.v7.widget.Toolbar
            机器人:ID =@ + ID /工具栏
            机器人:layout_width =match_parent
            机器人:layout_height =?ATTR / actionBarSize
            机器人:ATTR / colorPrimary后台=
            应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light
            应用程序:layout_scrollFlags =滚动| enterAlways/>


        < android.support.design.widget.TabLayout
            机器人:ID =@ + ID /标签
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT/>

    < /android.support.design.widget.AppBarLayout>

    < android.support.v4.view.ViewPager
        机器人:ID =@ + ID / viewpager
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>

< /android.support.design.widget.CoordinatorLayout>
 

解决方案

您应该将你的FAB的 CoordinatorLayout 里面。 事情是这样的:

 < android.support.design.widget.CoordinatorLayout>

    < android.support.design.widget.AppBarLayout>

        < android.support.v7.widget.Toolbar
            应用程序:layout_scrollFlags =滚动| enterAlways/>

        < android.support.design.widget.TabLayout />

    < /android.support.design.widget.AppBarLayout>

    < android.support.v4.view.ViewPager
        应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>

    < android.support.design.widget.FloatingActionButton
        机器人:ID =@ + ID /晶圆厂
        机器人:layout_gravity =结束|底/>

< /android.support.design.widget.CoordinatorLayout>
 

然后就可以以这种方式加入RecyclerView的viewPager里面:

 转接适配器=新的适配器(getSupportFragmentManager());
adapter.addFragment(新RecyclerViewFragment(),TAB1);
viewPager.setAdapter(适配器);
 

,其中RecyclerViewFragment布局是:

 < android.support.v7.widget.RecyclerView
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID / recyclerView
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>
 

I am using FAB button along with RecyclerView in a Fragment. This Fragment is an instance of a TabViewPager. I am having a issue with the FAB button. I have placed the RecyclerView and the fab button inside a FrameLayout, where the FAB buttton is positioned bottom right. Now the problem that I am facing is the FAB button is not fully visible. Its half of the portion is hidden as shown in the screenshot below. Can any one help me to solve this issue. Thanks in advance.

Note: The FAB is aligning properly once it is scrolled. The problem arises only if it is ideal (before scrolling done).

fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="10dp"
        app:backgroundTint="@color/red"
        android:src="@drawable/ic_done"/>
</FrameLayout>

tabviewpagerlayout.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"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


        <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/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />


        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

解决方案

You should move your FAB inside the CoordinatorLayout. Something like this:

<android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.Toolbar
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.design.widget.TabLayout/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_gravity="end|bottom"/>

</android.support.design.widget.CoordinatorLayout>

Then you can add the RecyclerView inside the viewPager in this way:

Adapter adapter = new Adapter(getSupportFragmentManager());
adapter.addFragment(new RecyclerViewFragment(), "Tab1");
viewPager.setAdapter(adapter);

where the RecyclerViewFragment layout is:

 <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

这篇关于浮动操作按钮没有显示的片段里​​面全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆