我尝试了以下代码在android中的表格布局,而不使用xml文件。但是我没有在android模拟器上得到我的屏幕,但得到了错误,因为“该应用程序已经停止了精确的操作,请再试一次。”在android中的表格布局
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class Tablelayout extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
LayoutParams params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(params);
tv.setTextColor(Color.RED);
TableRow tr=new TableRow(this);
tr.addView(tv);
TableLayout tl=new TableLayout(this);
TableLayout.LayoutParams layoutparams=new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tl.addView(tr);
this.addContentView(tl, layoutparams);
}
}
我建议你使用调试器运行你的应用程序,看看logcat告诉你什么。错误消息通常非常具有描述性。 –
Logcat显示运行时错误.... –