Android Tabs和CoordinatorLayout,需要添加一行textViews
Android Tabs and CoordinatorLayout, need to add a row of textViews
Android Studio 3.5.1。使用选项卡式 Activity 模板。 CoordinatorLayout 的东西我真的不懂。
<?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=".ChecklistActivity">
<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/AppTheme.AppBarOverlay">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
app:tabMode="scrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
效果很好。在每个选项卡上使用带有 ListView 的选项卡等
但是,在屏幕底部,我想添加一行包含不同状态信息的 TextView。 (例如自开始以来的时间、计数等)所以我在 XML 的底部放置了一个 LinearLayout。并添加了几个 TextView。它显示在 Studio 的设计视图中。但是在顶部。但是当我在 phone 上启动该应用程序时,我在任何地方都看不到它。
简而言之,我如何使用这个 XML (CoordinatorLayout) 将这样一个 'status bar' 添加到屏幕底部的视图中?
使用 RelativeLayout
作为 CoordinatorLayout
中的第一个子项。有属性android:layout_height="wrap_content"
和android:layout_alignParentBottom="true"
到TextViews
。其余的,即ViewPager
和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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChecklistActivity">
<!-- You could even use a ScrollView -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
app:tabMode="scrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/lilayTextViews"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:id="@+id/lilayTextViews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!-- TextViews go here -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 1"/>
</LinearLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Android Studio 3.5.1。使用选项卡式 Activity 模板。 CoordinatorLayout 的东西我真的不懂。
<?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=".ChecklistActivity">
<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/AppTheme.AppBarOverlay">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
app:tabMode="scrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
效果很好。在每个选项卡上使用带有 ListView 的选项卡等
但是,在屏幕底部,我想添加一行包含不同状态信息的 TextView。 (例如自开始以来的时间、计数等)所以我在 XML 的底部放置了一个 LinearLayout。并添加了几个 TextView。它显示在 Studio 的设计视图中。但是在顶部。但是当我在 phone 上启动该应用程序时,我在任何地方都看不到它。
简而言之,我如何使用这个 XML (CoordinatorLayout) 将这样一个 'status bar' 添加到屏幕底部的视图中?
使用 RelativeLayout
作为 CoordinatorLayout
中的第一个子项。有属性android:layout_height="wrap_content"
和android:layout_alignParentBottom="true"
到TextViews
。其余的,即ViewPager
和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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChecklistActivity">
<!-- You could even use a ScrollView -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
app:tabMode="scrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/lilayTextViews"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:id="@+id/lilayTextViews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!-- TextViews go here -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 1"/>
</LinearLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>