我希望能够在列表视图的标题中放置一个“图像滑块”。因此,用户可以滑动浏览图像,然后当他们开始滚动页面时,滑块会滚动到视图之外。
我用 ViewPager 得到了我想要的滑块。现在,我需要做的就是将它插入到列表视图的标题中,但这似乎给我带来了重大问题。
我这样添加寻呼机:
ViewPager pager = (ViewPager) inflater.inflate(R.layout.featured_event, listView, false);
FeaturedEventAdapter featuredAdapter = new FeaturedEventAdapter( getFragmentManager() );
pager.setAdapter( featuredAdapter );
listView.addHeaderView( pager );
我收到以下错误:
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.v4.view.ViewPager
现在,要注意的关键是,如果我在列表视图之外显示它,这将非常好。
编辑:featured_event xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="200dip">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal" >
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/car" />
</LinearLayout>
</android.support.v4.view.ViewPager>