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 控件
没有显示我动态添加的按钮
解决方案 »
- android上文本文档阅读器的分页问题
- android游戏图片拼接的问题
- android里类似桌面上应用程序列表抽屉的控件是什么?
- 求android 2.3talkback.apk
- textview的动态更新问题
- Android中获取TD网络的P-CCPCH RSCP(场强),急,在线等!
- HttpURLConnection post数据
- 谁能帮我写把下面这个 android 定义的按键 改成自动按键 自动触发 自动点击之后进入下一个界面
- 安装Genymotion时出错,求大神指导该怎么做
- android studio 不能走shadowsocks吗?
- 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
其他的都不显示问题是,那个没有按照内容 来显示长度