我有一个问题,每次询问时似乎都有不同的解决方案,并给我带来很大的困扰。我试图在其他SO问题中使用解决方案,但都没有成功。 我有一个Activity初始化一个ViewPager,一个工具栏和一个TabLayout。有两个选项卡,这两个选项卡都使用片段实现。问题是 我的片段与微调,回收视图,按钮和文本字段放在一起。在这些小部件中,只有recyclerView显示前两项丢失, 强迫我相信微调器隐藏在我的AppLayoutBar后面,并且textField和按钮位于屏幕下方。我的问题是,我如何让我的片段的布局 出现在标签下方屏幕的可见部分?下面是这两个片段和主要活动的布局文件如何使我的Fragment布局符合在主Activity中创建的选项卡?
片段:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:entries="@array/status"
>
</Spinner>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list"
android:paddingTop="20dp"
android:layout_below="@+id/spinner"
android:layout_above="@+id/editText"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:inputType="textMultiLine"
android:id="@+id/editText"
android:hint="@string/goal_edit_text_hint"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:maxLines="5"
android:minLines="1"
android:scrollHorizontally="false"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/addButton"
android:layout_toStartOf="@+id/addButton" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/add_button_text"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textAppearance="?android:textAppearanceLarge"
android:layout_alignParentEnd="true"
android:drawableLeft="@drawable/math"
android:id="@+id/addButton" />
</RelativeLayout>
主要活动
<?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">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="612dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_gravity="center" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/header"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>