选项卡布局覆盖片段的一部分,layout_below不起作用 [英] Tab Layout covering parts of fragment, layout_below not working

查看:58
本文介绍了选项卡布局覆盖片段的一部分,layout_below不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个UserAreaActivity,它的布局带有tabLayout.每个选项卡都是其自己的片段,但是在每个片段布局中,tabLayout覆盖了片段布局的顶部.我尝试使用android:layout_below并为其指定tabLayout的ID,但它无法正常工作.这是我的片段代码:

So I have a UserAreaActivity that has a layout with tabLayout. Each one of the tabs is its own fragment, however in each fragments layout the tabLayout covers the top of the fragments layout. I have tried using the android:layout_below and giving it the id of the tabLayout but it isnt working properly. Here is my fragments code:

<RelativeLayout 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"
android:layout_below="@+id/tabLayout"
tools:context="com.example.aleksandr.godspeedinvestments.OfferFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    <TextView
        android:text="After Repair Value"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/afRepValTV" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/afRepValueET"
        android:hint="After Repair Value" />

    <TextView
        android:text="Closing Cost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cc1TV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cc1OutTV" />

    <TextView
        android:text="Agents Fee"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/afTV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/afOutTV" />

    <TextView
        android:text="Repairs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/repTV" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/repET"
        android:hint="Repairs" />

    <View
        android:id="@+id/SplitLine_hor1"
        android:layout_width="match_parent"
        android:layout_height= "2dp"
        android:background="@android:color/darker_gray" />

    <TextView
        android:text="Net"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/netTV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/netOutTV" />

    <TextView
        android:text="Closing Cost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cc2TV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cc2OutTV" />

    <TextView
        android:text="Holding Cost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/holdCostTV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/holdCostOutTV" />

    <TextView
        android:text="Profit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/profitTV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/profitOutTV" />
    <View
        android:id="@+id/SplitLine_hor2"
        android:layout_width="match_parent"
        android:layout_height= "2dp"
        android:background="@android:color/darker_gray" />

    <TextView
        android:text="Offer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/offerTV" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/offerOutTV" />
    </LinearLayout>

</RelativeLayout>

这是我的UserAreaActivity.xml文件

And here is my UserAreaActivity.xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_user_area"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.aleksandr.godspeedinvestments.UserAreaActivity">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    >
    <include
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        layout="@layout/toolbar_layout"
        />

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabLayout"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextAppearance="@style/MyTabStyle"
        ></android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/viewPager"
    ></android.support.v4.view.ViewPager>
</RelativeLayout>

为澄清所有这些,应包括在片段布局中

To clarify all of this should be included in the fragments layout

推荐答案

正如@Mike M指出的那样,在ViewPager中添加属性"layout_below".并给您的AppBarLayout一个ID.您的UserAreaActivity.xml将如下所示.

As @Mike M pointed out, add the attribute "layout_below" in your ViewPager. And give an ID to your AppBarLayout. Your UserAreaActivity.xml will look like this.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_user_area"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.aleksandr.godspeedinvestments.UserAreaActivity">
    <android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:id="@+id/toolbarLayout"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    >
        <include
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        layout="@layout/toolbar_layout"
       />
       <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabLayout"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextAppearance="@style/MyTabStyle"
        ></android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbarLayout"
    android:id="@+id/viewPager"
    ></android.support.v4.view.ViewPager>
</RelativeLayout>

这篇关于选项卡布局覆盖片段的一部分,layout_below不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆