Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android仿天貓精品頁列表界面WIN8風格列表Listview實現

android仿天貓精品頁列表界面WIN8風格列表Listview實現

編輯:關於Android編程

即將做的項目需要弄天貓的這個效果,於是做了本DEMO。。。。。本代碼仿天貓ANDROID客戶端,精品頁面的列表界面,為了提高開發效率,本代碼使用了Afinal框架,用於加載網絡圖片,為了節省時間,使用了普通的LISTVIEW實現,後續大家可用支持下拉刷新,上拉更多的列表組件替代。本代碼絕對可運行。代碼編碼UTF-8。。。。。   核心代碼:

package android88.app.listview.demo.adapter;  
  
import java.util.List;  
  
import net.tsz.afinal.FinalBitmap;  
  
import android.R.integer;  
import android.content.Context;  
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.ImageView;  
import android88.app.listview.demo.R;  
  
public class Win8ListAdapter extends BaseAdapter {  
    List<String> _ImgsURL;  
    int _ItemCountNumber; // 列表總條數  
    int _AItemShowImgNumber = 3; // 列表每條顯示圖片數  
    Context _Context;  
    FinalBitmap _FinalBitmap;  
  
    public Win8ListAdapter(Context context, List<String> imgsURL) {  
        _Context = context;  
        _ImgsURL = imgsURL;  
        if (imgsURL.size() % _AItemShowImgNumber == 0) {  
            _ItemCountNumber = imgsURL.size() / _AItemShowImgNumber;  
        } else {  
            _ItemCountNumber = imgsURL.size() / _AItemShowImgNumber + 1;  
        }  
        _FinalBitmap = FinalBitmap.create(_Context);// 初始化FinalBitmap模塊  
    }  
  
    @Override  
    public int getCount() {  
        return _ItemCountNumber;  
    }  
  
    @Override  
    public Object getItem(int position) {  
        return null;  
    }  
  
    @Override  
    public long getItemId(int position) {  
        return position;  
    }  
  
    static class ViewHold {  
        ImageView subImageView1;  
        ImageView subImageView2;  
        ImageView subImageView3;  
    }  
  
    @Override  
    public View getView(int position, View convertView, ViewGroup parent) {  
        ViewHold _ViewHold = new ViewHold();  
  
        if (position % 2 == 0) {  
            convertView = LayoutInflater.from(_Context).inflate(  
                    R.layout.item_one, null);  
        } else {  
            convertView = LayoutInflater.from(_Context).inflate(  
                    R.layout.item_two, null);  
        }  
        _ViewHold.subImageView1 = (ImageView) convertView  
                .findViewById(R.id.subItem1);  
        _ViewHold.subImageView2 = (ImageView) convertView  
                .findViewById(R.id.subItem2);  
        _ViewHold.subImageView3 = (ImageView) convertView  
                .findViewById(R.id.subItem3);  
  
        for (int i = 0; i < _AItemShowImgNumber; i++) {  
            int index = position * _AItemShowImgNumber + i;  
            if (index >= _ImgsURL.size()) {  
                break;  
            } else {  
                if (i == 0) {  
                    _ViewHold.subImageView1.setVisibility(View.VISIBLE);  
                    _FinalBitmap.display(_ViewHold.subImageView1, _ImgsURL.get(index));  
                } else if (i == 1) {  
                    _ViewHold.subImageView2.setVisibility(View.VISIBLE);  
                    _FinalBitmap.display(_ViewHold.subImageView2, _ImgsURL.get(index));  
                } else if (i == 2) {  
                    _ViewHold.subImageView3.setVisibility(View.VISIBLE);  
                    _FinalBitmap.display(_ViewHold.subImageView3, _ImgsURL.get(index));  
                }  
            }  
        }  
        return convertView;  
    }  
  
}  

 


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved