2:3:4:5:6:7:" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

2010.06.05日志:Android Gallery左右循環(huán)旋轉(zhuǎn)方

系統(tǒng) 1820 0

如圖:

2

先在attr.xml里寫(xiě)個(gè)Gallery的樣式

      
        1:  
      
      
        <?
      
      
        xml 
      
      
        version
      
      =
      
        "1.0" 
      
      
        encoding
      
      =
      
        "utf-8"
      
      
        ?>
      
    
      
        2:  
      
      
        <
      
      
        resources
      
      
        >
      
    
      
        3:  
      
      
            <
      
      
        declare-styleable 
      
      
        name
      
      =
      
        "Gallery"
      
      
        >
      
    
      
        4:  
      
      
                <
      
      
        attr 
      
      
        name
      
      =
      
        "android:galleryItemBackground" 
      
      
        />
      
    
      
        5:  
      
      
            </
      
      
        declare-styleable
      
      
        >
      
    
      
        6:  
      
      
      
      
        <!-- 定義Layout外部resources 的xml文件,用來(lái)改變Layout的背景圖 -->
      
    
      
        7:  
      
      
      
      
        </
      
      
        resources
      
      
        >
      
    
      
        8:  
      
      
      
    

然后在mainActivity里的OnCreate里:

      
        1:  
      
      setContentView(R.layout.
      
        main
      
      );
    
      
        2:  
      
    
      
        3:  
      
      
        imageAdapter 
      
      = 
      
        new 
      
      myImageAdapter(
      
        this
      
      );
    
      
        4:  
      
    
      
        5:  
      
      
        gallery 
      
      = (Gallery) findViewById(R.id.
      
        Gallery_preView
      
      );
    
      
        6:  
      
      
        imageView 
      
      = (ImageView) findViewById(R.id.
      
        ImageView_photo
      
      );
    
      
        7:  
      
    
      
        8:  
      
      
        gallery
      
      .setAdapter(
      
        imageAdapter
      
      );
    
      
        9:  
      
      
        gallery
      
      .setSelection(200);
      
        //設(shè)置Gallery的起始位置
      
    

下面是imageAdapter的類(lèi),它繼承BaseAdapter

圖片資源:

      
        1:  
      
      
        protected int
      
      [] 
      
        myImageIds 
      
      = { R.drawable.
      
        vista_1
      
      , R.drawable.
      
        vista_2
      
      ,
    
      
        2:  
      
                  R.drawable.
      
        vista_3
      
      , R.drawable.
      
        vista_4
      
      , R.drawable.
      
        vista_5
      
      ,
    
      
        3:  
      
                  R.drawable.
      
        vista_6
      
      , };
    

構(gòu)造里:

      
         1:  
      
      
        public 
      
      myImageAdapter(Context context) {
    
      
         2:  
      
      
        mContext 
      
      = context;
    
      
         3:  
      
      
        /* 使用res/values/attr.xml中的<declare-styleable>定義的Gallery屬性 */
      
    
      
         4:  
      
      
      
      TypedArray typed_array = context
    
      
         5:  
      
                      .obtainStyledAttributes(R.styleable.
      
        Gallery
      
      );
    
      
         6:  
      
      
        mGalleryItemBackground 
      
      = typed_array.getResourceId(
    
      
         7:  
      
                      R.styleable.
      
        Gallery_android_galleryItemBackground
      
      , 0);
    
      
         8:  
      
      
        /* 讓對(duì)象的styleable 屬性能夠反復(fù)使用 */
      
    
      
         9:  
      
      
      
      typed_array.recycle();
    
      
        10:  
      
          }
    
      
        11:  
      
    

getCount()方法:

      
        1:  
      
      
        @Override
      
    
      
        2:  
      
      
      
      
        public int 
      
      getCount() {
    
      
        3:  
      
      
        // 
      
      
        TODO 
      
      
        Auto-generated method stub
      
    
      
        4:  
      
      
                // return myImageIds.length;
      
    
      
        5:  
      
      
      
      
        return 
      
      Integer.
      
        MAX_VALUE
      
      ;
    
      
        6:  
      
          }
    

getView()方法:

      
         1:  
      
      
        @
      
      
        Override
      
    
      
         2:  
      
      
      
      
        public 
      
      
        View getView(
      
      
        int 
      
      
        position, View convertView, ViewGroup parent) {
      
    
      
         3:  
      
      
                ImageView i = 
      
      
        new 
      
      
        ImageView(
      
      
        mContext
      
      
        );
      
    
      
         4:  
      
      
      
    
      
         5:  
      
      
      
      
        if 
      
      
        (position < 0) {
      
    
      
         6:  
      
      
                    position = position + 
      
      
        myImageIds
      
      
        .
      
      
        length
      
      
        ;
      
    
      
         7:  
      
      
                }
      
    
      
         8:  
      
      
                i.setImageResource(
      
      
        myImageIds
      
      
        [position % 
      
      
        myImageIds
      
      
        .
      
      
        length
      
      
        ]);
      
    
      
         9:  
      
      
                i.setScaleType(ImageView.ScaleType.
      
      
        FIT_XY
      
      
        );
      
    
      
        10:  
      
      
                i.setLayoutParams(
      
      
        new 
      
      
        Gallery.LayoutParams(128, 128));
      
    
      
        11:  
      
      
                i.setBackgroundResource(
      
      
        mGalleryItemBackground
      
      
        );
      
    
      
        12:  
      
      
      
      
        return 
      
      
        i;
      
    
      
        13:  
      
      
            }
      
    

2010.06.05日志:Android Gallery左右循環(huán)旋轉(zhuǎn)方法


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 久久欧美精品欧美九久欧美 | 男人女人真曰批的视频动态 | 亚洲成人在线视频播放 | 在线欧美精品一区二区三区 | 美女视频黄的免费视频网页 | 99国产精品高清一区二区二区 | 亚洲欧美日韩国产vr在线观 | 羞羞的视频在线免费观看 | 久久综合在线 | 免费精品美女久久久久久久久 | 精品国产第一国产综合精品 | 四虎精品成人免费视频 | 中文精品久久久久中文 | 国产精品综合一区二区三区 | 国产激情一级毛片久久久 | 毛片色 | 欧美精品一区二区三区在线 | 黄色男人的天堂 | 国产普通话自拍 | 欧美成人天天综合天天在线 | 在线观看年轻的母亲 | 久久精品国产亚洲片 | 真人一级一级特黄高清毛片 | 天天操精品| 91久国产在线观看 | 老司机午夜性大片免费 | 亚洲成人www | 国产五月色婷婷六月丁香视频 | 国产四区| 哪个网站能看毛片 | 中文字幕在线亚洲 | 亚洲一级毛片在线播放 | 天天干天天爽天天操 | 超激情碰碰碰啪在线视频 | 一二三区在线观看 | 一级毛片一级毛片 | 久久精品国产亚洲沈樵 | 国产精品久久久久久久小唯西川 | 欧美高清性粉嫩交 | 久操国产 | 国产高清美女一级毛片久久 |