Boa*_*rdy 11 tabs android android-layout android-fragments android-recyclerview
我的android项目中有Tab栏和ViewPager的问题.该应用程序具有一个活动,它包含一个标签布局,然后有一个代表每个标签的片段.
当活动打开时,它会发布到API以获取一些数据,并将数据放入数据适配器中,以便在每个片段中进行Recycler View和Card布局.
回收者视图将包含3个项目,但只显示2个项目,因为第一个项目隐藏在工具栏和/或标签栏下,如下面的屏幕截图所示.
下面是我的活动的布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.BoardiesITSolution.CritiMonApp.AppsActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill" />
</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_behaviour="@string/appbar_scrolling_view_behaviour" />-->
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
下面是片段的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<view
android:id="@+id/recycler_view"
class="android.support.v7.widget.RecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
下面是卡片布局的布局
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:elevation="5dp">
<TextView
android:id="@+id/txtApplicationName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:maxLines="3"
android:padding="8dp"
android:textColor="#222"
android:textSize="15dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
下面是上面提到的屏幕截图,显示了问题.我已经像素化了一些文字,但它应该是我的意思,应该有3个项目,但第一项隐藏在标签栏下面.
感谢您的任何帮助,您可以提供
fre*_*ptf 25
编辑:正如下面@smeet和@hardik所建议的那样,添加滚动行为app:layout_behavior="@string/appbar_scrolling_view_behavior"应该在保留滚动行为的同时解决问题.仅当视图是协调器布局的直接子级时,滚动行为才有效.
老答案
只需在垂直LinearLayout中包装您的appbar布局和viewpager
<android.support.design.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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.BoardiesITSolution.CritiMonApp.AppsActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
//appbar layout
//viewpager
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
来自文档,CoordinatorLayout is a super-powered FrameLayout.所以你可以期待典型的"在其他视图之上查看视图"的FrameLayout行为.
| 归档时间: |
|
| 查看次数: |
8225 次 |
| 最近记录: |