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

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

2010.06.05日志:Android Gallery左右循環旋轉方

系統 1906 0

如圖:

2

先在attr.xml里寫個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文件,用來改變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);
      
        //設置Gallery的起始位置
      
    

下面是imageAdapter的類,它繼承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
      
      , };
    

構造里:

      
         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:  
      
      
        /* 讓對象的styleable 屬性能夠反復使用 */
      
    
      
         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左右循環旋轉方法


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美日韩精品一区二区三区 | 久久久中文字幕 | 国产99久久久国产精品 | 国产乳摇福利视频在线观看 | 久久国产热视频 | 午夜性啪啪A片免费AAA毛片 | 精品国产福利在线 | 日日操av| 欧美成人精品 | 免费精品久久 | 99热久久这里只精品国产9 | 高清激情小视频在线观看 | 色综合天天综合中文网 | 亚洲免费网站 | 人人99 | 亚洲视频在线视频 | 免费网站国产 | 午夜视频免费 成人 | 免费观看一级特黄欧美大片 | cosplay裸体福利写真 | 成人免费视频网站在线观看 | 日韩在线你懂的 | 国产精品视频免费的 | 久久网在线 | 欧美成人在线免费观看 | 国产精品久久久久久久一区探花 | 91看片淫黄大片欧美看国产片 | 国产片侵犯亲女视频播放 | 日本高清免费不卡在线 | 国精品日韩欧美一区二区三区 | 欧美日韩一区二区三 | 中文欧美日韩 | 欧美精品一区二区蜜臀亚洲 | 日日干夜夜操s8 | 九九久久国产精品 | 久久久久无码国产精品一区 | 天天操综合 | 国产99999| 久久精品黄色 | 日韩视频在线精品视频免费观看 | 波多久久夜色精品国产 |