2016-12-16 47 views
0

所以我有一个UserAreaActivity,它具有tabLayout的布局。每个选项卡都有自己的片段,但是在每个片段布局中,tabLayout都会覆盖片段布局的顶部。我已经尝试使用android:layout_below并给它tabLayout的id,但它不能正常工作。这里是我的代码片段:标签布局覆盖部分碎片,layout_below不工作

<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文件

<?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> 

编辑:为了澄清这一切应该包括在片段布局This is what should be included in the activity

However, as you can see the tab layout is blocking the top of the fragment from being displayed

+1

将'layout_below'属性放在'ViewPager'上。 –

+0

你能分享一个截图吗 – Athul

回答

3

正如@Mike M指出的,在ViewPager中添加属性“layout_below”。并给你的编号AppBarLayout。你的UserAreaActivity.xml看起来像这样。

<?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> 
+0

非常感谢你的快速回复,你做得非常好!你不知道还有多少其他问题和youtube视频,我通过查找答案,并找不到它,非常非常感谢你! –

+0

很高兴我能帮忙:) –