现在有一个问题,想用TableLayout与TableRow来布局,实现每次动态删除TableRow里的内容后后一行的自动能往前一行补(当然说的前提就是多余2行数据),现在这样初始的效果就是每次删除就往前或当前位置推进,不能往上一行推进,我希望的就是如果中间哪行某个位置删除了,最终效果中间不会有空,空到最后一个位置的内容。只要是能实现这种功能,不一定要使用TableLayout与TableRow布局。缺陷代码如下:
TestActivity.javaimport android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;public class TestActivity extends Activity{
private Button[] jb;
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01);
jb=new Button[50];
for(int i=0;i<50;i++)
{
jb[i]=new Button(this);
}
for(int i=0;i<5;i++)
{
final TableRow tr=new TableRow(this);
for(int j=0;j<10;j++)
{
final int nm=50;
if((10*i+j)<nm)
{
final int tt=10*i+j;
jb[(10*i+j)].setText(""+(10*i+j));
jb[(10*i+j)].setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
tr.removeView(jb[tt]);
}
});
tr.addView(jb[(10*i+j)]);
}
}
tableLayout.addView(tr, new TableLayout.LayoutParams(FP, WC));
}
}
} layout.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="horizontal">
<TableLayout android:layout_width="fill_parent" android:id="@+id/TableLayout01"
android:layout_height="wrap_content">
</TableLayout>
</ScrollView>
</LinearLayout>
TestActivity.javaimport android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;public class TestActivity extends Activity{
private Button[] jb;
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01);
jb=new Button[50];
for(int i=0;i<50;i++)
{
jb[i]=new Button(this);
}
for(int i=0;i<5;i++)
{
final TableRow tr=new TableRow(this);
for(int j=0;j<10;j++)
{
final int nm=50;
if((10*i+j)<nm)
{
final int tt=10*i+j;
jb[(10*i+j)].setText(""+(10*i+j));
jb[(10*i+j)].setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
tr.removeView(jb[tt]);
}
});
tr.addView(jb[(10*i+j)]);
}
}
tableLayout.addView(tr, new TableLayout.LayoutParams(FP, WC));
}
}
} layout.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="horizontal">
<TableLayout android:layout_width="fill_parent" android:id="@+id/TableLayout01"
android:layout_height="wrap_content">
</TableLayout>
</ScrollView>
</LinearLayout>
解决方案 »
- 求指教,或者说是探讨一个问题
- 问一个native surface的问题
- Android socket:客服端接收文件!
- android客户端怎么访问gsoap的webserver服务
- android pin&puk密碼解鎖
- 什么情况会出现unable to open database file
- 手写功能。急求!!!
- 新建xml时出错
- System.exit(0);app未退出,求高手解惑
- android listview长按报错
- android中像这些属性怎么记,怎样在SDK中查找style="?android:attr/progressBarStyleHorizontal"
- 如何获取并保存AlertDialog中EditText的输入值?
你去看看ListView的用法,删除一行数据后重新绑定一下数据源并调用一个方法通知listview更新界面就可以了。很简单的。