关于Fragment中嵌套不能包含include自定义标题的解决方案.txt

说明:
        在正常的用fragment作为数据源应用于viewPager中,是不可以直接在viewPager中插入include自定义标题的,
        如果想要插入自定义标题并且让标题随着Fragment同步滑动,在Fragment的xml代码中执行以下步骤即可:
        1.将包含Fragment元素的准内容页面content.xml的布局改为线性布局LinerLayout,竖直排列
        2.在ViewPager的上方在插入一个LinerLayout的线性布局(这是固定不动的标题栏),
        3.将include自定义标题栏放入ViewPager上方的LinerLayout布局中,
        4.将每一个Fragment元素的xml文件页面也改为线性布局,
        在布局文件上方插入用LinerLayout包含的include自定义标题文件
        到此就可以实现自定义标题随着Fragment同步滚动的效果
        代码如下:
主内容页面:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.work.suishenji.acvitity.ContentActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">
        <include layout="@layout/title_layout"></include>
    </LinearLayout>//此种标题固定不会改变
    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </android.support.v4.view.ViewPager>
每一个Fragment.xml文件

<LinearLayout 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:id="@+id/fg_jsb"
    tools:context="com.work.suishenji.fragment.JsbFragment"
    android:orientation="vertical">

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">        
        <include layout="@layout/title_layout"></include>
    </LinearLayout>//这是可以随着fragent一起滚动的的标题栏

  <android.support.v7.widget.RecyclerView
      android:id="@+id/rv_frgjsb"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

  </android.support.v7.widget.RecyclerView>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值