加入Viewpager为到ListView页眉 [英] adding Viewpager as a header to a listView

查看:136
本文介绍了加入Viewpager为到ListView页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想程序,显示一些图像和ListView下面一些数据的viewpager活动..但我的问题是,我可以在屏幕的最后一部分滚动显示列表视图我想使viewpager滚动与ListView,所以我想过把它作为标题。这里是我的XML文件

I'm trying to program an activity that show a viewpager with some images and listview below with some data .. but my problem is that I can scroll only the listview on the last part of the screen I wanted to make the viewpager scrollable with the listview so I thought about putting it as header .. here's my XMl file

<TableLayout 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"
tools:context=".MainActivity" >

<com.devsmart.android.ui.HorizontalListView
    android:id="@+id/sectionsList"
    android:layout_width="wrap_content"
    android:layout_height="25dp"
    android:background="@drawable/menu_bg" />

<include layout="@layout/main_screen_components" />

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

和我写这篇文章在我的课

and I write this in my class

@Override
    protected void onPostExecute(List<News> result) {
        Utils.pagerNews(result);
        Utils.listNews(result);

        ImagePagerAdapter pAdapter = new ImagePagerAdapter(
                appManager.getPagerNews());
        pager.setAdapter(pAdapter);

        View headerView = getLayoutInflater().inflate(R.layout.main_screen_components , null , false);

        NewsListAdapter adapter = new NewsListAdapter(getBaseContext(),
                appManager.getListNews());
        listView.addHeaderView(headerView);
        listView.setAdapter(adapter);
        progress.dismiss();
    }

当我运行此code它给了我一个复制的寻呼机..固定一个具有数据和空单作为我的列表视图的头。当我删除,其中包括我的传呼机崩溃,当我尝试设置一个适配器连接到寻呼机..任何想法?

when I run this code it gives me a duplicated pager .. fixed one with the data and an empty one as an header of my listview .. when I remove which include my pager it crashes when I try to set an adapter to the pager .. any idea ?

推荐答案

刚刚成立viewPager的onTouchListener,像这样的:

just set viewPager's onTouchListener,like this:

viewPager.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    PointF downP = new PointF();
    PointF curP = new PointF();
    int act = event.getAction();
    if(act == MotionEvent.ACTION_DOWN || act == MotionEvent.ACTION_MOVE || act == MotionEvent.ACTION_UP){
      ((ViewGroup) v).requestDisallowInterceptTouchEvent(true);
      if (downP.x == curP.x && downP.y == curP.y) {
        return false;
      }
    }
    return false;
  }

这篇关于加入Viewpager为到ListView页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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