ViewPager在CoordinatorLayout显示不全

冯先森 2016-11-15 01:32:52
功能是写在Fragmen中的,不是Activity中,标题XML代码中属性也设置了,ViewPager的XML代码属性也设置了,但是现在的问题是滑动AppBarLayout的内容是可以滑动的,但是滑动ViewPager的内容不好使,只能水平滑动,不能垂直滑动,正常情况下,ViewPager的内容应该延伸到屏幕外,但现在只是显示部分



<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_firstpager_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<!--标题界面-->
<LinearLayout
android:id="@+id/fragment_firstpager_title"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/title_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
app:layout_scrollFlags="scroll|enterAlways">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:src="@drawable/logo" />

<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />

<ImageView
android:id="@+id/fragment_firstpager_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/xiaoxi" />

<View
android:layout_width="23dp"
android:layout_height="match_parent" />

<ImageView
android:id="@+id/fragment_firstpager_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/jilu" />

<View
android:layout_width="23dp"
android:layout_height="match_parent" />

<ImageView
android:id="@+id/fragment_firstpager_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/saoyisao" />

<View
android:layout_width="13dp"
android:layout_height="match_parent" />

</LinearLayout>


<!--tab和导航-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EBEBEB">

<android.support.design.widget.TabLayout
android:id="@+id/fragment_firstpager_tablayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:tabGravity="center"
app:tabIndicatorColor="@color/tab_select"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/tab_select">

</android.support.design.widget.TabLayout>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/elevation" />
<!--导航-->
<LinearLayout
android:id="@+id/fragment_firstpager_guide"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="center"
android:orientation="vertical">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/daohang" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="导航" />

</LinearLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/fragment_firstpager_viewpager"
android:layout_width="match_parent"
android:layout_height="3000dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>


@Override
public View initView(Activity activity) {
View view = LayoutInflater.from(activity).inflate(R.layout.fragment_firstpager2,container,false);
fragment_firstpager_message = (ImageView) view.findViewById(R.id.fragment_firstpager_message);
fragment_firstpager_record = (ImageView) view.findViewById(R.id.fragment_firstpager_record);
fragment_firstpager_scan = (ImageView) view.findViewById(R.id.fragment_firstpager_scan);
fragment_firstpager_tablayout = (TabLayout) view.findViewById(R.id.fragment_firstpager_tablayout);
fragment_firstpager_guide = (LinearLayout) view.findViewById(R.id.fragment_firstpager_guide);
fragment_firstpager_viewpager = (ViewPager) view.findViewById(R.id.fragment_firstpager_viewpager);
haveStateScrollView = (CoordinatorLayout) view.findViewById(R.id.fragment_firstpager_scrollview);
fragment_firstpager_title = (LinearLayout) view.findViewById(R.id.fragment_firstpager_title);
return view;
}

@Override
protected void initListener(Activity activity) {

}

@Override
public void initDate(Activity activity) {
BaseActivityPagerAdapter pagerAdapter = new BaseActivityPagerAdapter(((MainActivity) activity).getSupportFragmentManager());
Bundle bundle = new Bundle();

pagerAdapter.addData(activity, pagerAdapter.new FragmentInfo(RecommandFragment.class, bundle), "推荐");
pagerAdapter.addData(activity, pagerAdapter.new FragmentInfo(FreeClassFragment.class, bundle), "免费课");
pagerAdapter.addData(activity, pagerAdapter.new FragmentInfo(ChooseClassFragment.class, bundle), "选课程");
pagerAdapter.addData(activity, pagerAdapter.new FragmentInfo(SeeLiveFragment.class, bundle), "看直播");
pagerAdapter.addData(activity, pagerAdapter.new FragmentInfo(OneMoneyFragment.class, bundle), "一元课");
pagerAdapter.addData(activity, pagerAdapter.new FragmentInfo(SubjectFragment.class, bundle), "专题");

fragment_firstpager_viewpager.setAdapter(pagerAdapter);
fragment_firstpager_tablayout.setupWithViewPager(fragment_firstpager_viewpager);

}
...全文
1319 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
teny_s 2017-07-10
  • 打赏
  • 举报
回复
这个怎么解决的楼主
liuwei1995 2017-03-27
  • 打赏
  • 举报
回复
大牛,能不能提供一下源码?
jscoolstar 2017-03-27
  • 打赏
  • 举报
回复
使用toolbar试试呢,viewpager本身就是不能竖直滑动的,其实是在滑动coordinatelayout,它会看appbarlayout里的toolbar的layout_scrollFlags来决定是否向上改变位置
shenweiww 2017-03-27
  • 打赏
  • 举报
回复
加个scrollview?

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧