码迷,mamicode.com
首页 > 其他好文 > 详细

【Andord真】SlideMenu+ViewPagerIndictor双滑动边栏+滑动导航条

时间:2015-09-20 14:28:30      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

采取SlideMenu达到的效果侧边栏:

setContentView是设置主背景的布局

setBehindContentView是设置左边菜单的布局

setSecondaryMenu是设置右边的布局


setShadowWidth是设置阴影的宽度

setBehindWidth是设置有效的拉出宽度

setMode是设置开启左右两边的菜单


採用ViewPagerIndictor实现滑动的导航栏和页面布局

当中採用TabPageIndicator做可滑动导航栏

ViewPager做滑动的布局

首先要设置导航栏的样式

    <style name="HomeUpTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    
        <item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
   
    </style>
   
    <style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
        <item name="android:dividerPadding">10dp</item>
        <item name="android:paddingLeft">20dp</item>
        <item name="android:paddingRight">20dp</item>
        <item name="android:paddingTop">10dp</item>
        <item name="android:paddingBottom">10dp</item>
        <item name="android:textSize">10pt</item>
        <item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item>
        <item name="android:textColor">#000000</item>
        <item name="android:fadingEdge">horizontal</item>
        <item name="android:fadingEdgeLength">8dp</item>
        <item name="android:background">@drawable/selectitle</item>
        <item name="android:gravity">center</item>
    </style>
在代码中
ViewPager里面可设置载入

布局适配器PagerAdapter重写instantiateItem方法

碎片适配器FragmentStatePagerAdapter重写Fragment getItem()的方法

最后把两者关联起来

indicatorView.setViewPager(pager);

完整代码:


public class MainAct extends SlidingActivity {

	SlidingMenu slidingMenu;
	TabPageIndicator indicatorView;
	ViewPager pager;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setBehindContentView(R.layout.slide_behind);
		setContentView(R.layout.slide_main);
		slidingMenu = getSlidingMenu();
		slidingMenu.setBehindOffset(300);
		slidingMenu.setBehindWidth(400);
		slidingMenu.setSecondaryMenu(R.layout.slide_second);
		// slidingMenu.setTouchModeAbove(SlidingMenu.LEFT_RIGHT);
		slidingMenu.setShadowWidth(100);
		slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
		indicatorView = (TabPageIndicator) findViewById(R.id.indicator);
		pager = (ViewPager) findViewById(R.id.pager);

		pager.setAdapter(new Myadapter());
		pager.setOffscreenPageLimit(8);
		indicatorView.setOnTabReselectedListener(new OnTabReselectedListener() {

			@Override
			public void onTabReselected(int position) {
				Toast.makeText(getApplicationContext(), position + "", 3000)
						.show();
				// TODO Auto-generated method stub
				pager.setCurrentItem(position);
			}
		});

		pager.setCurrentItem(0);
		indicatorView.setViewPager(pager);
		indicatorView.setClickable(true);

	}

	class Myadapter extends PagerAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 8;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			// TODO Auto-generated method stub
			return "--" + position + "--";
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			// TODO Auto-generated method stub
			((ViewPager) container).removeViewAt(position);

			super.destroyItem(container, position, object);
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			// TODO Auto-generated method stub
			return arg0 == arg1;
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			// TODO Auto-generated method stub
			ImageView imageView = new ImageView(getApplicationContext());
			imageView.setImageBitmap(BitmapFactory.decodeResource(
					getResources(), R.drawable.flower));
			container.addView(imageView);
			return imageView;
			// return super.instantiateItem(container, position);
		}

	}

}



      

版权声明:本文博主原创文章。博客,未经同意不得转载。

【Andord真】SlideMenu+ViewPagerIndictor双滑动边栏+滑动导航条

标签:

原文地址:http://www.cnblogs.com/hrhguanli/p/4823313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!