实现导航栏的左右滑动效果
2011-10-13 08:50
483 查看
<RelativeLayout android:id="@id/titleBar" android:layout_width="fill_parent" android:layout_height="40.0dip"/> //titlebar 内容 public NewsVideo() { String[] arrayOfString1 = new String[7]; arrayOfString1[0] = "推荐"; arrayOfString1[1] = "电视剧"; arrayOfString1[2] = "电影"; arrayOfString1[3] = "纪录片"; arrayOfString1[4] = "动画片"; arrayOfString1[5] = "综艺"; arrayOfString1[6] = "新闻"; this.strLblTile = arrayOfString1; this.currentTitlePosition = 0; this.oldTitlePosition = currentTitlePosition; } //动态加载titleBar LayoutInflater inflater= LayoutInflater.from(this);; View view = inflater.inflate(R.layout.titlebar, null); RelativeLayout localRelativeLayout2 = (RelativeLayout)this.findViewById(R.id.titleBar); localRelativeLayout2.addView(view); //初始化titleBar NewsVideo nv= new NewsVideo(); linearLayTitle=(LinearLayout) this.findViewById(R.id.linearLayTitle); initTitleBar(); // private void initTitleBar() { TextView[] arrayOfTextView1 = new TextView[this.strLblTile.length]; this.lblArr = arrayOfTextView1; Resources localResources = getResources(); for (int i = 0; ; ++i) { int j = this.lblArr.length; if (i >= j) { TextView[] arrayOfTextView2 = this.lblArr; int k = this.currentTitlePosition; arrayOfTextView2[k].setTextColor(-1); TextView[] arrayOfTextView3 = this.lblArr; int l = this.currentTitlePosition; arrayOfTextView3[l].setBackgroundResource(R.drawable.nav_light); return; } TextView[] arrayOfTextView4 = this.lblArr; TextView localTextView1 = new TextView(this); arrayOfTextView4[i] = localTextView1; TextView localTextView2 = this.lblArr[i]; int i1 = Mconst.screenwidth * 67 / 320; ///System.out.println("i1 "+i1); localTextView2.setWidth(i1); TextView localTextView3 = this.lblArr[i]; int i2 = Mconst.screenheight * 40 / 480; localTextView3.setHeight(i2); //System.out.println("i2 "+i2); this.lblArr[i].setTextSize(14); this.lblArr[i].setGravity(17); TextView localTextView4 = this.lblArr[i]; String str = this.strLblTile[i]; localTextView4.setText(str); TextView localTextView5 = this.lblArr[i]; int i3 = localResources.getColor(R.color.white); localTextView5.setTextColor(i3); LinearLayout localLinearLayout = this.linearLayTitle; TextView localTextView6 = this.lblArr[i]; //System.out.println("第"+i+"个"+lblArr[i].getText()); localLinearLayout.addView(localTextView6); int i4 = i; TextView localTextView7 = this.lblArr[i4]; localTextView7.setOnClickListener(new TitleBarListener(this,i4)); } } class TitleBarListener implements View.OnClickListener{ int i; Context con; public TitleBarListener(NewsVideo newsVideo, int i4) { // TODO Auto-generated constructor stub con=newsVideo; this.i=i4; } @Override public void onClick(View v) { // TODO Auto-generated method stub currentTitlePosition=i; if(currentTitlePosition!=oldTitlePosition){ lblArr[oldTitlePosition].setBackgroundDrawable(null); oldTitlePosition=currentTitlePosition; lblArr[currentTitlePosition].setBackgroundResource(R.drawable.nav_light); } switch(currentTitlePosition){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: Toast.makeText(con, "您正在浏览 "+lblArr[currentTitlePosition].getText()+" 页面", Toast.LENGTH_SHORT).show(); break; default: break; } } }
相关文章推荐
- Android实现导航栏的左右滑动效果
- 基于jQuery和hwSlider实现内容左右滑动切换效果附源码下载(一)
- Android使用ViewPager实现左右循环滑动及轮播效果
- Android实现左右滑动指引效果
- Android中实现整个视图切换的左右滑动效果
- android仿系统Launcher界面,实现分屏,左右滑动效果(ViewSwitcher)
- Android中实现左右滑动的指引效果
- Android实现左右滑动指引效果
- 手机端图片左右滑动效果实现
- listview中item的左右滑动效果的实现
- [Andoid点滴]左右滑动效果的实现
- Android之新闻客服端顶部导航栏Tab点击和左右滑动实现切换界面
- Android实现左右滑动指引效果
- Android使用ViewPager实现左右循环滑动及轮播效果
- 一个圆环上有好多控件,实现左右滑动以及近大远小的效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android 左右滑动切换页面或Activity的效果实现
- h5用swiper结合angularjs实现手机浏览器左右滑动切换图片的效果
- android 实现 波纹效果+图片左右无限滑动缩放效果