Android实现导航栏的左右滑动效果

Android实现导航栏的左右滑动效果


<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;
 
                }
 
         }
 
   } 


上一篇:关键帧动画:@keyframes


下一篇:javascript继承--原型链的 继承