【发布时间】:2014-03-19 16:22:05
【问题描述】:
我关注 How can I create a table with borders in Android? 这非常有帮助,但在我的情况下无法创建仅显示行边框的列边框。
我的代码:
TableLayout.LayoutParams tableLayoutParams = new
TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
TableLayout tableLayout = new TableLayout(getContext());
tableLayout.setBackgroundColor(Color.WHITE);
tableRowParams = new TableRow.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
tableRowParams.setMargins(1, 1, 1, 1);
//tableRowParams.weight = 1;
for (i = 0; i < row + 1; i++) {
tableRow = new TableRow(getContext());
tableRow.setGravity(Gravity.CENTER_VERTICAL);
//tableRow.setBackgroundColor(Color.BLACK);
tableRow.setPadding(2, 2, 2, 2);
tableRow.setBackgroundResource(R.drawable.cell_shape_new);
for (j = 0; j < col + 1; j++) {
LinearLayout ll = new LinearLayout(getContext());
ll.setLayoutParams(new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
ll.setOrientation(1);
TextView textView = new TextView(getContext());
textView.setTextSize(25);
textView.setTextColor(Color.BLACK);
textView.setGravity(Gravity.CENTER);
//Display required field
}
}
}
R.drawable.cell_shape_new
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#000000"/>
</shape>
我的输出:
如何在此处放置列边框。
【问题讨论】:
-
嘿,你能解释一下吗?我不明白你想在哪里显示列边框?
-
为每个单元格设置一个背景Drawable,九个补丁drawable是你的朋友
-
我将所有单元格设置在 cell_shape.xml 之上。但没有得到。看看我编辑的问题。
标签: android android-tablelayout