【问题标题】:NestedScrollView cut/overlay bottom of nested FragmentsNestedScrollView 剪切/覆盖嵌套片段的底部
【发布时间】:2017-03-28 04:53:55
【问题描述】:

我对@9​​87654325@ 有疑问,因为它切断了视野。

我有 FragmentA 的架构:

<RelativeLayout>
<android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.AppBarLayout>
        <android.support.design.widget.CollapsingToolbarLayout>
            <ImageView/>
            <android.support.v7.widget.Toolbar/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView>
        <LinearLayout>
            <FrameLayout> 
                <!-- fragment added dynamically-->
            </FrameLayout>
            <FrameLayout>
                <!-- fragment added dynamically-->
            </FrameLayout>
            <FrameLayout>
                <!-- fragment added dynamically-->
            </FrameLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    <android.support.design.widget.FloatingActionButton/>
</android.support.design.widget.CoordinatorLayout>

我正在向每个 FrameLayout 添加动态片段。

当我第一次运行应用程序时,我做了 SS:Screen at first time 我在每个布局中都添加了填充以查看发生了什么。 greenCoordinatorLayoutredNestedScrollView, orangeLinearLayoutNestedScrollView里面。

现在我将 FragmentA 替换为 FragmentB 并再次回到 FragmentA 并且我有这样的东西:wrong dispaly

有人知道我做错了什么吗?

这是我对FragmentA 的整个布局:

<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:orientation="vertical">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorP"
    android:padding="5dp"
    android:layout_above="@+id/przyciski">

    <android.support.design.widget.AppBarLayout

        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginBottom="25dp"
            app:expandedTitleMarginEnd="0dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                android:contentDescription="descp" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollableview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorRedCalendar"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:padding="5dp">

        <LinearLayout
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:orientation="vertical"
            android:padding="5dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/frameForInfo"
                android:minHeight="100dp"
                android:focusableInTouchMode="true">

            </FrameLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/frameForCalendar"
                android:minHeight="100dp"
                android:focusableInTouchMode="true">

            </FrameLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/frameForGraph"
                android:minHeight="100dp"
                android:focusableInTouchMode="true">
            </FrameLayout>

        </LinearLayout>

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

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end"
        app:backgroundTint="@color/colorAccent"
        android:id="@+id/floatingButtonLog" />

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

编辑: 我编译:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.jjoe64:graphview:4.2.1'
}

我将Fragments 添加到FrameLayout 中:

infoFragment = new InfoFragment();
    infoFragment.setLogs(mapLogIn, mapLogOut, monthToDispaly, yearToDispaly);
    infoFragment.setPracownik(mPracownik);


    if (getChildFragmentManager().findFragmentByTag("INFO") == null) {
        getChildFragmentManager()
                .beginTransaction()
                .add(R.id.frameForInfo, infoFragment, "INFO")
                .commit();
    }else {
        getChildFragmentManager()
                .beginTransaction()
                .replace(R.id.frameForInfo, infoFragment, "INFO")
                .commit();
    }

我如何将FragmentA 替换为FragmentB

((AppCompatActivity)getActivity()).getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.frameForFragment, edit)
                        .addToBackStack(null)
                        .commit();

以及我如何从FragmentB 回到FragmentA

getFragmentManager().beginTransaction().remove(AddingPerson.this).commit();

                    if (getFragmentManager().getBackStackEntryCount()>0){
                        getFragmentManager().popBackStack();
                    }

看起来 NestedScrollView 在底部被剪掉了,因为(如果你看 ss)底部没有填充框。

我注意到当我回到FragmentA(显示错误时)并替换NestedScrollView 内的片段时,NestedScrollView 的底部出现了。

Here is YT video.

更新

我找到了临时答案here。我补充说:

android:layout_gravity="fill_vertical"
android:layout_marginBottom="?attr/actionBarSize"

但是据说这个错误在 v22.2.1 中已修复,但似乎没有。有人知道吗?

【问题讨论】:

    标签: android android-fragments android-coordinatorlayout android-nestedscrollview


    【解决方案1】:

    当旋转屏幕或显示软键盘时,接受的答案会增加一个边距。我通过将 OnGlobalLayoutListener() 添加到主视图并从侦听器内部调用 requestLayout() 到此类视图来修复。

    【讨论】:

      【解决方案2】:

      尝试使用:

      android:layout_marginBottom="?attr/actionBarSize"
      

      在您的 NestedScrollView 中

      【讨论】:

      • 是的,我做到了,它有帮助,但我仍然不满意,因为它应该没有这个。
      • 它以您想要的方式帮助了您?如果是,那你为什么不满意?
      【解决方案3】:

      尝试在你的嵌套滚动视图中添加它

      android:fillViewport="true"
      

      【讨论】:

      • 我做到了。没有任何改变
      猜你喜欢
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多