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"