当前位置:编程学习 > wap >>

求助 关于tablerow的对其问题

我的这个程序的功能就是点一下一个按钮,添加两个tablerow,一行文本框,一行按钮,可出来按钮总是跟着文本框的长度变化~~555,哭死了
比如刚开始是这样:

输入字母后就成这样了


请问这是为什么啊?
public void addtablerow( ){
//自动完成文本框
final String i="1";
ArrayAdapter<String> ausuadpter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,this.asus);
AutoCompleteTextView auto1=new AutoCompleteTextView(this);
auto1.setAdapter(ausuadpter);
auto1.setCompletionHint("请选择华硕主板型号");
//数字
final EditText text=new EditText(this);
text.setText(i);
text.setRawInputType(InputType.TYPE_CLASS_NUMBER);

//按钮+
Button button1=new Button(this);
button1.setText("+");
button1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String a;
a=text.getText().toString();
int num =Integer.parseInt(a);//将字符串转换成int
num++;
String c = Integer.toString(num); 
text.setText(c);
}
});
//按钮-
Button button2=new Button(this);
button2.setText("-");
button2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
String a;
a=text.getText().toString();
int num =Integer.parseInt(a);//将字符串转换成int
num--;
String c = Integer.toString(num); 
text.setText(c);

}
});
//添加到tablerow
TableRow tablerow1=new TableRow(this);
TableRow tablerow2=new TableRow(this);
tablerow1.addView(auto1);
tablerow2.addView(button1);
tablerow2.addView(text);
tablerow2.addView(button2);
TableLayout asus=(TableLayout)findViewById(R.id.tablelayout1);
//添加到布局管理器
asus.addView(tablerow1);
asus.addView(tablerow2);

}
android 求助 --------------------编程问答-------------------- 千万别沉啊!!!! --------------------编程问答-------------------- 自己顶自己啊!!!! --------------------编程问答-------------------- 为什么要用tableRow呢?
tableRow类似单元格的形式....上面那个变了下面也要跟着变 --------------------编程问答-------------------- 下面这个布局可以这样
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <Button
            android:layout_weight="1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="+" />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="1" />
        <Button
            android:layout_weight="1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="+" />
      
    </TableRow>

这样就不会跟着上面那个变了

或者你可以改成其它布局方式.不用tableRow --------------------编程问答-------------------- EditText不要放在TableRow里面,宽度设成match_parent
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,