android - 将布局重力更改为中心将 TextView 隐藏在选项卡后面
问题描述
我正在尝试将 a 居中TextView
在 aNestedScrollView
中。这NestedScrollView
是选项卡式布局片段的一部分。如果layout_gravity
的TextView
设置为默认值,TextView
则会正确显示 。但是,一旦我将其更改为center
前几行,TextView
它们就隐藏在选项卡后面。
这是一个片段的代码NestedScrollView
<?xml version="1.0" encoding="utf-8"?>
<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>
这是选项卡式活动的代码:
<?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"
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"
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>
你能告诉我如何在不丢失内容的情况下将TextView
内部居中吗?NestedScrollView
PS:我已经检查了使用的代码fillViewPort=true
,但它不起作用。
Android Studio 在创建 Tabbed Activity 后提供的默认值如下:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<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"
android:theme="@style/Theme.BuddhaPoojaMarathi.AppBarOverlay">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?actionBarSize"
android:padding="@dimen/appbar_padding"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我只删除了 TextView 和一个浮动按钮。删除浮动按钮并没有改变任何东西。但是在删除之后,TextView
我遇到了上述问题。
解决方案
推荐阅读
- html - 我的图像代码在 Visual Studio 2019 中不起作用
- highcharts - 您可以添加到 highcharts 图表中的 y 轴的最大数量是多少?
- java - Java 堆栈跟踪不使用 log4j2 打印
- java - 支持无状态和有状态用法的 JPA 代码
- javascript - 如何设置对象变量并通过方法返回它们 - 打字稿?
- c# - 如果 Json 键之一包含点,如何为 Json 序列化声明匿名类型?
- java - Java 8 无法在 Macos Catalina 中写入文件
- ios - 从 UIScrollview 中删除内容和框架布局指南
- powershell - 在 Powershell 中,我如何使用变量从文件夹权限中删除组
- c - 指针取消引用的不同行为