main.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id = "@+id/mainLayout"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
/>
<EditText
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:minLines = "1"
android:maxLines = "1"
android:gravity = "top|fill_vertical"
android:numeric = "decimal"
android:id="@+id/sumEdit"
/>
<TableLayout
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:id="@+id/tableLayout"
>
</TableLayout>
</LinearLayout>
public class MainAvitivy extends Activity {
private TableLayout tableLayout = null; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init() ;
} public void init(){
tableLayout = (TableLayout) this.findViewById(R.id.tableLayout);
tableLayout.setStretchAllColumns(false);
TableRow tableRow = new TableRow(tableLayout.getContext());
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.setId(10000);
for (int i = 0; i <= 9 ; i++) {
Button button = new Button(this);
button.setText(" " + i + " ");
button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT ,ViewGroup.LayoutParams.WRAP_CONTENT));
tableRow.addView(button);
Log.i("syso" , i + "");
}
tableLayout.addView(tableRow);
}}
添加不了 ,
运行后,界面顶部只有一个TextView 和 EditText 控件
没有显示我动态添加的按钮
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id = "@+id/mainLayout"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
/>
<EditText
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:minLines = "1"
android:maxLines = "1"
android:gravity = "top|fill_vertical"
android:numeric = "decimal"
android:id="@+id/sumEdit"
/>
<TableLayout
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:id="@+id/tableLayout"
>
</TableLayout>
</LinearLayout>
public class MainAvitivy extends Activity {
private TableLayout tableLayout = null; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init() ;
} public void init(){
tableLayout = (TableLayout) this.findViewById(R.id.tableLayout);
tableLayout.setStretchAllColumns(false);
TableRow tableRow = new TableRow(tableLayout.getContext());
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.setId(10000);
for (int i = 0; i <= 9 ; i++) {
Button button = new Button(this);
button.setText(" " + i + " ");
button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT ,ViewGroup.LayoutParams.WRAP_CONTENT));
tableRow.addView(button);
Log.i("syso" , i + "");
}
tableLayout.addView(tableRow);
}}
添加不了 ,
运行后,界面顶部只有一个TextView 和 EditText 控件
没有显示我动态添加的按钮
解决方案 »
- MediaPlayer只有声音没图象,在线等啊!!!
- Android 开发:如何连接到服务器上的mysql数据库
- Android 音乐播放器 波普 怎么开发
- 联想a68e手机如何获取root权限 如何刷机啊?
- eclipse中使用so库
- 哪位写过Android关于多线程的应用?
- Android开发_联系人相关
- 请问下各位JAVA JDK与JAVA SE,EE,ME之间的关系
- android 通过代码实现USB连接共享PC网络????
- NestedScrollView嵌套XRecyclerView缓慢滑动卡顿
- ScrollView 和 OnDraw()的问题
- android音乐播放器 查询最近播放的音乐
解决办法
button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT ,ViewGroup.LayoutParams.WRAP_CONTENT));
改成
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT ,LayoutParams.WRAP_CONTENT));
用的是tablerow.layoutParams
其他的都不显示问题是,那个没有按照内容 来显示长度