这是问题所在:文本视图边框小于包含“Loooooong Teeeeext”的列中的单元格大小
我使用这个背景可绘制
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#1e11d5"/>
</shape>
和这个表格的布局
<LinearLayout android:id="@+id/ll_country"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ScrollView android:id="@+id/ScrollView11"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true">
<HorizontalScrollView
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/layout_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dip">
<!-- <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="0,1" android:id="@+id/country_table">
</TableLayout> -->
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
这是生成表格的代码
for (int current = 0; current < 100 ; current++) {
row = new TableRow(this);
TextView t;
for(int i =0 ; i < 20 ; i++){
t = new TextView(this);
t.setTextSize(20);
t.setText(" text "+i+" ");
t.setBackgroundDrawable(border);
if((i== 4) && (current == 5)){
t.setText(" looooooong teeeeext ");
}
//t.setWidth(20);
t.setTextColor(Color.BLACK);
row.addView(t,LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
t.setBackgroundDrawable(border);
}
table.addView(row, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
layout_table.addView(table, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));