我在我的应用程序中使用SwipeyTabs.我不确定如何填写标签内容.它甚至没有任何自己的xml.
我正在使用这样的标签:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_swipey_tabs); initViewPager(4,0xFFFFFFFF,0xFF000000); mSwipeyTabs = (SwipeyTabsView) findViewById(R.id.swipey_tabs); mSwipeyTabsAdapter = new SwipeyTabsAdapter(this); mSwipeyTabs.setAdapter(mSwipeyTabsAdapter); mSwipeyTabs.setViewPager(mPager); } private void initViewPager(int pageCount,int backgroundColor,int textColor) { mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ExamplePagerAdapter(this,pageCount,backgroundColor,textColor); mPager.setAdapter(mPagerAdapter); mPager.setCurrentItem(1); mPager.setPageMargin(1); }
这里是activity_swipey_tabs.xml布局:
<android.ex.com.viewpager.extension.SwipeyTabsView android:id="@+id/swipey_tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#3B3B3B" /> <View android:id="@+id/colorline" android:layout_width="fill_parent" android:layout_height="2dip" android:layout_below="@+id/swipey_tabs" android:background="#FF91A438" /> <View android:id="@+id/blackline" android:layout_width="fill_parent" android:layout_height="1dip" android:layout_below="@+id/colorline" android:background="#FF000000" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/blackline" />
有没有例子或教程?
任何支持都会很棒.
解决方法
SwipeyTabs的标签就像虚拟布局,我的意思是他们没有自己定义的布局.您应该动态定义每个组件.
让我详细解释一下.例如,您需要一个ListView(自定义).你创建了这样的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="70dp" android:padding="5dp" android:background="#ffffff" > <ImageView android:id="@+id/imageView1" android:layout_width="80dp" android:layout_height="60dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:src="@drawable/i1" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/imageView1" android:layout_alignParentRight="true" android:textColor="@android:color/black" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/textView2" android:layout_alignTop="@+id/imageView1" android:textColor="@android:color/black" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/imageView1" android:layout_toRightOf="@+id/imageView1" android:textColor="@android:color/black" android:textAppearance="?android:attr/textAppearanceSmall" /> </RelativeLayout>
现在你需要一个ArrayAdapter来调整这个自定义ListView,我不包括ArrayAdapter.
因此,在PagerAdapter类中,定义ListView并使用此布局.例如:
@Override public Object instantiateItem(View container,int position) { ListView v = new ListView( mContext ); //test_list_layout which is above TestAdapter adapter = new TestAdapter(mContext,R.layout.test_list_layout,objs); v.setAdapter( adapter ); ((ViewPager)container ).addView( v,0 ); v.setSelection( scrollPosition[ position ] ); v.setOnScrollListener( new OnScrollListener() { public void onScrollStateChanged( AbsListView view,int scrollState ){} public void onScroll( AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount ) { scrollPosition[ pos ] = firstVisibleItem; } }); return v; }
现在它运作良好.如果您需要更多选项卡,请使用position参数作为分隔符,如if(position == 0).在这里你需要这一行:
((ViewPager) container).removeView((View) container);
就这样.我希望,很清楚.