Android 列表布局制作表格
[一篮饭特稀原创,转载请注明出处http://www.cnblogs.com/wanghafan/archive/2012/07/30/2615512.html ]
basic.xml
View Code
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="fill_parent" 4 android:layout_height="fill_parent" 5 android:orientation="vertical" > 6 7 <LinearLayout 8 android:layout_width="fill_parent" 9 android:layout_height="50dip" 10 android:orientation="horizontal" > 11 12 <Button 13 android:id="@+id/btn_Basic_Connect" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="@string/btn_Basic_Connect" /> 17 18 <Button 19 android:id="@+id/btn_Basic_DisConnect" 20 android:layout_width="wrap_content" 21 android:layout_height="wrap_content" 22 android:text="@string/btn_Basic_DisConnect" /> 23 24 <Button 25 android:id="@+id/btn_Basic_Export" 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:text="@string/btn_Basic_Export" /> 29 </LinearLayout> 30 31 <TableLayout 32 android:id="@+id/listView_Basic" 33 android:layout_width="fill_parent" 34 android:layout_height="wrap_content" 35 android:orientation="horizontal" > 36 37 <TableRow> 38 <TextView 39 android:id="@+id/MAC" 40 style="@style/listview_title" 41 android:text="MAC" /> 42 43 <TextView 44 android:id="@+id/SSID" 45 style="@style/listview_title" 46 android:text="SSID" /> 47 48 <TextView 49 android:id="@+id/SignalQuality" 50 style="@style/listview_title" 51 android:text="信号质量" /> 52 53 <TextView 54 android:id="@+id/Channel" 55 style="@style/listview_title" 56 android:text="频段" /> 57 58 <TextView 59 android:id="@+id/Frequency" 60 style="@style/listview_title" 61 android:text="频率" /> 62 63 <TextView 64 android:id="@+id/RSSI" 65 style="@style/listview_title" 66 android:text="RSSI" /> 67 68 <TextView 69 android:id="@+id/Noise" 70 style="@style/listview_title" 71 android:text="Noise" /> 72 73 <TextView 74 android:id="@+id/SNR" 75 style="@style/listview_title" 76 android:text="SNR" /> 77 78 <TextView 79 android:id="@+id/Privacy" 80 style="@style/listview_title" 81 android:text="加密方式" /> 82 83 <TextView 84 android:id="@+id/Rate" 85 style="@style/listview_title" 86 android:text="连接速度" /> 87 88 <TextView 89 android:id="@+id/Status" 90 style="@style/listview_title" 91 android:text="网络状态" /> 92 </TableRow> 93 </TableLayout> 94 95 </LinearLayout>
BasicActivity.java
View Code
1 package fjpdi.android.activity; 2 3 import fjpdi.android.wifimanager.R; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.widget.Button; 7 import android.widget.TableLayout; 8 import android.widget.TableRow; 9 import android.widget.TextView; 10 11 public class BasicActivity1 extends MenuActivity 12 { 13 private Button btn_Connect, btn_DisConnect, btn_Export_WirelessInfo; 14 private TableLayout listView_Basic; 15 private TableRow tRow; 16 private TextView tv; 17 18 @Override 19 public void onCreate(Bundle savedInstanceState) 20 { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.basic); 23 findModels(); 24 findViews(); 25 setListensers(); 26 27 listView_Basic = (TableLayout) findViewById(R.id.listView_Basic); 28 for (int i = 0; i < 10; i++) 29 { 30 tRow = new TableRow(this); 31 for (int j = 0; j < 11; j++) 32 { 33 tv = new TextView(this); 34 tv.setText("aaaa" + j); 35 tRow.addView(tv); 36 } 37 listView_Basic.addView(tRow); 38 } 39 } 40 41 private void findModels() 42 { 43 } 44 45 private void findViews() 46 { 47 btn_Connect = (Button) findViewById(R.id.btn_Basic_Connect); 48 btn_DisConnect = (Button) findViewById(R.id.btn_Basic_DisConnect); 49 btn_Export_WirelessInfo = (Button) findViewById(R.id.btn_Basic_Export); 50 } 51 52 private void setListensers() 53 { 54 btn_Connect.setOnClickListener(btn_Connect_Click); 55 btn_DisConnect.setOnClickListener(btn_DisConnect_Click); 56 btn_Export_WirelessInfo.setOnClickListener(btn_Export_WirelessInfo_Click); 57 } 58 59 private Button.OnClickListener btn_Connect_Click = new Button.OnClickListener() 60 { 61 public void onClick(View v) 62 { 63 } 64 }; 65 private Button.OnClickListener btn_DisConnect_Click = new Button.OnClickListener() 66 { 67 public void onClick(View v) 68 { 69 } 70 }; 71 private Button.OnClickListener btn_Export_WirelessInfo_Click = new Button.OnClickListener() 72 { 73 public void onClick(View v) 74 { 75 } 76 }; 77 }
style.xml
View Code
1 <resources xmlns:android="http://schemas.android.com/apk/res/android"> 2 3 <style name="listview_title"> 4 <item name="android:layout_height">20dip</item> 5 <item name="android:textSize">10sp</item> 6 <item name="android:background">#62AFC1</item> 7 <item name="android:layout_width">45dip</item> 8 <item name="android:gravity">center</item> 9 </style> 10 11 <style name="listview_content"> 12 <item name="android:layout_height">20dip</item> 13 <item name="android:textSize">10sp</item> 14 <item name="android:layout_width">45dip</item> 15 </style> 16 17 </resources>
string.xml
View Code
1 <resources> 2 <string name="app_name">WLAN测试优化软件</string> 3 <string name="btn_Connect">连接</string> 4 <string name="btn_DisConnect">断开</string> 5 <string name="btn_Export_WirelessInfo">导出</string> 6 <string name="btn_Refresh">刷新</string> 7 <string name="btn_Back">返回</string> 8 </resources>