要到另一个片段,当浮动操作按钮的问题 [英] Floating action button issue when going to another fragment

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

问题描述

我运行pre-建造活动的Andr​​oid工作室1.5.1提供(滚动活动),并面临着奇怪的问题。当我点击 FAB 我要到另一个片段但像正巧波纹画面上有些事情,我的晶圆厂放在上面我的片段仍然是可见的。任何机构可以知道如何解决这个问题?

I run pre-built activity which Android-studio 1.5.1 provide (Scrolling Activity) and face strange issue. When I click on FAB I want to go to another fragment But some thing like bellow picture Happened and My Fab placed on Top of my fragment and still is visible. can any body knows How to fix this ?

下面是滚动活动的XML,我添加的FrameLayout把我的片段:

Here is xml of Scrolling Activity that I add frameLayout to put my fragment :

    <?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"
    android:fitsSystemWindows="true"
    tools:context="ir.apio.myapplication.ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <include layout="@layout/content_scrolling" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />


    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>

content_scrolling.xml:

content_scrolling.xml :

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="ir.apio.myapplication.ScrollingActivity"
    tools:showIn="@layout/activity_scrolling">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:text="@string/large_text" />

</android.support.v4.widget.NestedScrollView>

我的晶圆厂ClickListener:

My fab ClickListener :

fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.frame,new TestFragment())
                        .commit();
            }
        });

也是我TestFragment:

And also my TestFragment :

public static class TestFragment extends Fragment {

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_test,container,false);
            return view;
        }
    }

下面是屏幕截图,才去新片段

Here is screen-shot before going to new fragment

在这里输入的形象描述

下面将要新片段时的屏幕截图

Here is screen-shot when going to new fragment

进去后新片段

推荐答案

究其原因,你仍然看到FAB是的海拔的,它指的是屏幕上的看法深度。它会影响哪些元素是高于或低于另一个,他们投下的阴影(例如FAB坐在主要内容的顶部并蒙上了一层阴影)。

The reason you are still seeing the FAB is elevation, which refers to a views depth on the screen. It affects which elements are above or below one another and the shadows they cast(for example a FAB sits on top of the main content and casts a shadow).

在FAB在默认情况下会产生一定的海拔高度,您可以覆盖使用高程属性,如:应用:海拔=4DP。其它元素将在0dp水平

The FAB by default will have some elevation, which you can override using the elevation attribute, eg app:elevation="4dp". The other elements will be at the 0dp level.

在你的情况,你已经把最后的FrameLayout在布局文件,我presume这就是你加载你的片段之中。这样做是不实际更换您的其他内容,而只是与你的FrameLayout的内容覆盖。

In your case, you've put the FrameLayout last in your layout file, and I presume that's where you are loading your fragment into. What this does is not actually replace your other content, but just cover it with the content of your FrameLayout.

它不包括FAB的原因,是因为FAB有一定的仰角和的FrameLayout没有。因此,尽管你已经把你的FrameLayout最后并通常会期望这是上面的FAB实际上有一个更高的高度将覆盖这一点。

The reason it doesn't cover the FAB, is because the FAB has some elevation and the FrameLayout doesn't. So although you've put your FrameLayout last and would normally expect that to be "on top", the FAB actually has a higher elevation which overrides that.

有一个速战速决,是给你的浮动操作按钮应用:海拔= 0dp 这将放回它在同一标高的一切和正常规则将适用的是的FrameLayout最后的,会在上面。

A quick fix, would be to give your floating action button app:elevation=0dp which would put it back on the same elevation level as everything else and the normal rules would apply, the FrameLayout is last and would be on top.

在现实中,只是把一个大的框架涵盖了previous内容通常不会是最好的事情做,你会想看看其他的方式来构建应用程序。

In reality, just putting a big frame covering the previous content is not usually the best thing to do and you would want to look at other ways to structure the app.

这篇关于要到另一个片段,当浮动操作按钮的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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