我的 tablayout/viewpager 有一個簡單的片段:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".pkgFragment.InputDataOverviewFragment"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@ id/abToolBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/BrightYellowCrayola"
>
<androidx.appcompat.widget.Toolbar
android:id="@ id/tbMenuIconWithTitle"
app:navigationIcon="@drawable/baseline_menu_24"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
>
<androidx.appcompat.widget.SearchView
android:id="@ id/svInputdata"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultQueryHint="@string/search_incometypes"
app:iconifiedByDefault="false"
app:searchIcon="@null"
app:queryBackground="@android:color/transparent"
app:submitBackground="@android:color/transparent"
android:imeOptions="flagNoExtractUi"
/>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:id="@ id/tabLayoutInputDataTypes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/BrightYellowCrayola"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_below="@id/tabLayoutInputDataTypes"
android:id="@ id/viewPagerInputDataTypes"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的片段在 tablayout 上被選中時顯示:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:focusableInTouchMode="true"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/rvListIncomeType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/zero_margin_when_normal"
android:paddingEnd="@dimen/zero_margin_when_normal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/fabAddDeleteIncomeType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:contentDescription="@string/add_incometype"
android:minHeight="48dp"
android:src="@drawable/baseline_person_add_24"
app:backgroundTint="@color/BrightYellowCrayola" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
問題是我的片段的高度與我的父片段匹配,這就是為什么片段的高度不完全適合我的 viewpager:

如您所見,浮動操作按鈕在下方一半消失,第一個工具列基本上是向上拖動的,并沒有完全出現。
處理帶有片段的 tablayouts 中的高度問題的正確解決方案是什么?
uj5u.com熱心網友回復:
為了使它作業,我洗掉了兩行(當前):
android:fitsSystemWindows="true"
和
app:layout_scrollFlags="scroll|enterAlways"
如果洗掉它是一個聰明的主意,我會及時通知您。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/323368.html
標籤:安卓 android-fragments android-viewpager 高度 浮动操作按钮
