Android中的TableLayout的简单使用

在Layout中加入TableLayout控件。

<TableLayout android:id="@+id/myTableLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="40dp"
    android:layout_marginTop="157dp" >
</TableLayout>

Code

public class MainActivity extends Activity {
    private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; 
    private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TableLayout myTableLayout = (TableLayout)this.findViewById(R.id.myTableLayout);
        //全部列自动填充空白处 
        myTableLayout.setStretchAllColumns(true);  
        for(int r = 1; r < 10; r ++)
        {
            TableRow tr = new TableRow(this);
            for(int c = 1; c < 5; c++)    
            {      
                TextView tv = new TextView(this);
                tv.setText("Row " + r + "  + Column " + c ); 
                tr.addView(tv);
            }
            myTableLayout.addView(tr,new TableLayout.LayoutParams(FP, WC)); 
        }  
    }
}

 效果图

Android中的TableLayout的简单使用

 



本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2013/03/18/2961245.html,如需转载请自行联系原作者

相关文章:

  • 2021-10-18
  • 2021-12-14
  • 2022-12-23
  • 2021-11-19
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-06-17
  • 2021-07-10
  • 2021-09-29
  • 2021-06-08
  • 2021-11-04
  • 2021-09-03
相关资源
相似解决方案