【发布时间】:2021-05-21 12:33:42
【问题描述】:
我正在尝试在 Tabbed 活动中实现滚动片段。片段内只有一个TextView,只要layout_gravity 没有更改,它就可以正常工作。但只要将layout_gravity 设置为center,TextView 的内容就会隐藏在选项卡后面。
代码如下:
Fragment
<androidx.core.widget.NestedScrollView 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=".Fragment_1">
<TextView
android:id="@+id/frag1_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/text_margin"
android:textSize="@dimen/text_medium"
android:textAlignment="center"
android:textColor="@color/black"
android:text="@string/buddha_vandana_mar" />
</androidx.core.widget.NestedScrollView>
还有ViewPager:
<androidx.coordinatorlayout.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"
tools:context=".PrayerActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true"
android:theme="@style/Theme.BuddhaPoojapathMarathi.AppBarOverlay">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
没有layout_gravity:center 如下所示:
【问题讨论】:
标签: android android-layout android-fragments layout-gravity