现在有一个问题,想用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>
解决方案 »
- android httpclient请求数据关闭问题
- 关于sqlite3中文查询的问题
- android之GridView的困惑
- android入门教程
- 通过surfaceflinger写屏,提示copybits failed
- 跪求:怎么设置HorizontalScrollView首列固定
- 请问Android中的多线程硬件机制是怎样的
- 求android Launcher的开发思路。或者源码。
- auto cannot be resolved or is not a field怎么解决啊?!!
- 小米手机调试时出现两个一模一样的设备
- android中像这些属性怎么记,怎样在SDK中查找style="?android:attr/progressBarStyleHorizontal"
- 如何获取并保存AlertDialog中EditText的输入值?
你去看看ListView的用法,删除一行数据后重新绑定一下数据源并调用一个方法通知listview更新界面就可以了。很简单的。