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

Android 類似HTML 中Table的網格Table

系統 3520 0
    package com.easyway.android.ui.tables;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
 * ListView自適應實現Table的類TableAdapter.java代碼如下:

	PS:TableCell是格單元的類,TableRow是表格行的類,TableRowView是實現表格行的組件。
	實現步驟:TableCell --> TableRow(TableRowView)-->ListView

 * @author longgangbai
 *
 */
public class TableAdapter extends BaseAdapter {   
    private Context context;   
    private List<TableRow> table;   
    public TableAdapter(Context context, List<TableRow> table) {   
        this.context = context;   
        this.table = table;   
    }   
    @Override   
    public int getCount() {   
        return table.size();   
    }   
    @Override   
    public long getItemId(int position) {   
        return position;   
    }   
    public TableRow getItem(int position) {   
        return table.get(position);   
    }   
    public View getView(int position, View convertView, ViewGroup parent) {   
        TableRow tableRow = table.get(position);   
        return new TableRowView(this.context, tableRow);   
    }   
    /** 
     * TableRowView 實現表格行的樣式 
     * @author hellogv 
     */   
    class TableRowView extends LinearLayout {   
        public TableRowView(Context context, TableRow tableRow) {   
            super(context);   
               
            this.setOrientation(LinearLayout.HORIZONTAL);   
            for (int i = 0; i < tableRow.getSize(); i++) {//逐個格單元添加到行    
                TableCell tableCell = tableRow.getCellValue(i);   
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(   
                        tableCell.width, tableCell.height);//按照格單元指定的大小設置空間    
                layoutParams.setMargins(0, 0, 1, 1);//預留空隙制造邊框    
                if (tableCell.type == TableCell.STRING) {//如果格單元是文本內容    
                    TextView textCell = new TextView(context);   
                    textCell.setLines(1);   
                    textCell.setGravity(Gravity.CENTER);   
                    textCell.setBackgroundColor(Color.BLACK);//背景黑色    
                    textCell.setText(String.valueOf(tableCell.value));   
                    addView(textCell, layoutParams);   
                } else if (tableCell.type == TableCell.IMAGE) {//如果格單元是圖像內容    
                    ImageView imgCell = new ImageView(context);   
                    imgCell.setBackgroundColor(Color.BLACK);//背景黑色    
                    imgCell.setImageResource((Integer) tableCell.value);   
                    addView(imgCell, layoutParams);   
                }   
            }   
            this.setBackgroundColor(Color.WHITE);//背景白色,利用空隙來實現邊框    
        }   
    }   
    /** 
     * TableRow 實現表格的行 
     * @author hellogv 
     */   
    static public class TableRow {   
        private TableCell[] cell;   
        public TableRow(TableCell[] cell) {   
            this.cell = cell;   
        }   
        public int getSize() {   
            return cell.length;   
        }   
        public TableCell getCellValue(int index) {   
            if (index >= cell.length)   
                return null;   
            return cell[index];   
        }   
    }   
    /** 
     * TableCell 實現表格的格單元 
     * @author hellogv 
     */   
    static public class TableCell {   
        static public final int STRING = 0;   
        static public final int IMAGE = 1;   
        public Object value;   
        public int width;   
        public int height;   
        private int type;   
        public TableCell(Object value, int width, int height, int type) {   
            this.value = value;   
            this.width = width;   
            this.height = height;   
            this.type = type;   
        }   
    }   
}  
  

?

?

    package com.easyway.android.ui.tables;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.Toast;

import com.easyway.android.ui.tables.TableAdapter.TableCell;
import com.easyway.android.ui.tables.TableAdapter.TableRow;
/**
 *  類似HTML 中Table的網格Table
 *          如何用ListView實現自適應的表格。GridView比ListView更容易實現自適應的表格,
 * 但是GridView每個格單元的大小固 定,而ListView實現的表格可以自定義每個格單元的大小,但
 * 因此實現自適應表格也會復雜些(格單元大小不一)。
 *        另外,GridView實現的表格可 以定位在具體某個格單元,而ListView實現的表格則
 * 只能定位在表格行。因此還是那句老話:根據具體的使用環境而選擇GridView 或者 ListView實現表格。
 *
 *          本文實現的ListView表格,可以每個格單元大小不一,文本(TextView)或圖片(ImageView)
 *做格單元的數據,不需要預先定義XML實現樣式(自適應的根本目標)。由于ListView置于
 *HorizontalScrollView中,因此對于列比較多/列數據比較長的數據表也能很好地適應其
 *寬度。
 *
 * @author longgangbai
 *
 */
public class AndroidHtmlTableActivity extends Activity { 
	    /** Called when the activity is first created. */   
	    ListView lv;   
	    @Override   
	    public void onCreate(Bundle savedInstanceState) {   
	        super.onCreate(savedInstanceState);   
	        setContentView(R.layout.main);   
	        this.setTitle("ListView自適應實現表格---hellogv");   
	        lv = (ListView) this.findViewById(R.id.ListView01);   
	        ArrayList<TableRow> table = new ArrayList<TableRow>();   
	        TableCell[] titles = new TableCell[5];// 每行5個單元    
	        int width = this.getWindowManager().getDefaultDisplay().getWidth()/titles.length;   
	        // 定義標題    
	        for (int i = 0; i < titles.length; i++) {   
	            titles[i] = new TableCell("標題" + String.valueOf(i),    
	                                    width + 8 * i,   
	                                    LayoutParams.FILL_PARENT,    
	                                    TableCell.STRING);   
	        }   
	        table.add(new TableRow(titles));   
	        // 每行的數據    
	        TableCell[] cells = new TableCell[5];// 每行5個單元    
	        for (int i = 0; i < cells.length - 1; i++) {   
	            cells[i] = new TableCell("No." + String.valueOf(i),   
	                                    titles[i].width,    
	                                    LayoutParams.FILL_PARENT,    
	                                    TableCell.STRING);   
	        }   
	        cells[cells.length - 1] = new TableCell(R.drawable.ic_launcher,   
	                                                titles[cells.length - 1].width,    
	                                                LayoutParams.WRAP_CONTENT,   
	                                                TableCell.IMAGE);   
	        // 把表格的行添加到表格    
	        for (int i = 0; i < 12; i++)   
	        {
	            table.add(new TableRow(cells));   
	        }
	        TableAdapter tableAdapter = new TableAdapter(this, table);   
	        lv.setAdapter(tableAdapter);   
	        lv.setOnItemClickListener(new ItemClickEvent());   
	    }   
	    class ItemClickEvent implements AdapterView.OnItemClickListener {   
	        @Override   
	        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,   
	                long arg3) {   
	            Toast.makeText(AndroidHtmlTableActivity.this, "選中第"+String.valueOf(arg2)+"行", 500).show();   
	        }   
	    }   
	}   
	 


  

?

?

效果圖如下:

Android 類似HTML 中Table的網格Table

Android 類似HTML 中Table的網格Table


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久福利在线 | 亚洲精品网站日本xxxxxxx | 99久久精品国产一区二区三区 | 色婷婷综合久久久中文字幕 | 精久久 | 国产精品成熟老女人 | 涩涩色综合亚洲悠悠色 | 男女污网站| 国产日韩一区二区三区 | 欧美在线成人影院 | 天天视频在线播放观看视频 | 日韩欧美一区二区三区不卡 | 最新中文在线视频 | 亚洲色域网 | 精久久| 欧美精品一区二区三区久久 | 国产成人啪精品视频免费网站软件 | 成人性a激情免费视频 | 亚洲国产一区二区三区四区五区 | 午夜精品一区二区三区免费视频 | 国产精品v欧美精品v日韩精品 | 亚洲高清在线观看看片 | 日韩伦理电影免费观看 | 日本人视频jizz页码69 | 日韩在线观看一区二区不卡视频 | 国产在线日本 | 多女多p多杂交视频在线观看 | 欧美高清hd| 欧美精品久久久久久久久老牛影院 | 一级色毛片 | 黄色av.com| 国产精品美女久久久久久 | 国产91成人精品亚洲精品 | 激情网五月天 | 嫩草影院国产 | 色综合久久天天综合绕观看 | 日本在线观看 | 精品精品国产高清a毛片 | 91麻豆精品久久久久蜜臀 | 成人三级视频 | 亚洲97 |