17

我已经为我的看法决定的基本协调的布局被截断。我张贴我的简单的一个片段:部分在屏幕底部(安卓)

<ListView 
    android:id="@+id/transferList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"></ListView> 

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="@dimen/activity_vertical_margin" 
    android:layout_marginRight="@dimen/activity_horizontal_margin" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ic_add_white" /> 

什么情况是,在FAB熄灭屏幕。这只是不是FAB,但其他具有cardviews/listviews的片段在屏幕底部被截断。我四处寻找解决方案,并提出了一个hacky解决方案:从工具栏删除财产应用程序:layout_scrollFlags =“scroll | enterAlways”。

我不明白是什么原因可能导致这种情况发生,以及如何解决上述问题。支持库中有一些错误吗?有没有更好的方法来解决这个问题?我遇到的另一个解决方案是从here - 将FAB按钮直接放在活动中的协调器布局下,并使其仅在您需要的片段中可见。对我来说,这似乎不是一个好的解决方案。另外,我的片段中的其他观点也被切断了。

+3

我删除了'app:layout_scrollFlags =“scroll | enterAlways | snap”'并且滚动工作正常,底部没有被切断。只是想问一下这个变化有什么意义?你遇到过这个问题的其他解决方案吗? –

+0

我发现只删除'scroll |'部分就足够了。希望通过这样做,会有比我完全删除'app:layout_scrollFlags'属性更少的可能影响(?) –

回答

1

这是因为您正在使用CoordinatorLayoutListView。您可以将您的实施更改为RecyclerView以实现正确的滚动。

查看我的回答here。这可能会帮助你。

+0

我和OP有同样的问题,并且我没有在我的ListView中使用'ViewPager'。 (我正在使用'WebView'。) –

+0

您可以尝试用其他布局替换CordinatorLayout并查看它是否仍然发生? – sha

+0

没关系,谢谢。根据我的回答,我已经找到了解决方案:http://stackoverflow.com/a/39735185/1617737 –

20

我已通过将工具栏app:layout_scrollFlags="scroll|enterAlways"属性更改为app:layout_scrollFlags="enterAlways"来修复此问题。

+2

如果我使用CollapsingToolbarLayout并且必须使用滚动属性,则会出现问题。 – Tefa

+0

适用于我,我不必在底部添加空间。 –

3

我有一个类似于你的布局:一个工具栏离开顶部和标签。对碎片的要求是拥有自己独立的FAB。

我不能直接在XML应付它,所以后来我钉这种方式:

活动布局

<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:fitsSystemWindows="true"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    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:layout_marginBottom="20dp" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways|snap" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabContentStart="72dp" 
     app:tabMode="scrollable" /> 

</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" /> 

片段布局:

<FrameLayout 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"> 

<include 
    android:id="@+id/scroll" 
    layout="@layout/content_activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|right|end" 
    android:src="@android:drawable/ic_input_add" 
    app:borderWidth="0dp" 
    app:fabSize="mini" 

    app:useCompatPadding="true" /> 

还有一些代码可以让FAB保持它的意图。 片段onCreateView:从工具栏layout_scrollFlags属性

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     final View rootView = inflater.inflate(R.layout.fragment_tabs2, container, false); 
     final FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); 
     final TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tabs); 
     final AppBarLayout appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.appbar); 
     appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 

      @Override 
      public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
       int maxAbsOffset = appBarLayout.getMeasuredHeight() - tabLayout.getMeasuredHeight(); 
       fab.setTranslationY(-maxAbsOffset - verticalOffset); 
      } 

     }); 

     return rootView; 
    } 
0

删除滚动。你应该有这样的东西: app:layout_scrollFlags="enterAlways|enterAlwaysCollapsed"