如何在TableLayout
直通代码中添加边框?
xml中的TableLayout
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
我的密码
TableLayout prices = (TableLayout)findViewById(R.id.tableLayout1);
prices.setStretchAllColumns(true);
prices.bringToFront();
for(int i = 0; i < 1; i++){
TableRow tr = new TableRow(this);
TextView c1 = new TextView(this);
c1.setText(equipHere);
c1.setTextColor(Color.BLACK);
c1.setTextSize(15);
TextView c2 = new TextView(this);
c2.setText("No of Days("+daysHere+")");
c2.setTextColor(Color.BLACK);
c2.setTextSize(15);
tr.addView(c1);
tr.addView(c2);
prices.addView(tr);
}
创建Gradient
成res\xml\table.xml
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#C0C0C0"
android:endColor="#505050"
android:angle="90"/>
<corners android:radius="2px" />
</shape>
并设置为您的TableLayout
背景
TableLayout table = (TableLayout)findViewById(R.id.tableLayout1);
table.setBackgroundDrawable(getResources().getDrawable(R.xml.table));
通过编程,您可以实现:
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[] {Color.parseColor("#C0C0C0"), Color.parseColor("#505050")});
gd.setGradientCenter(0.f, 1.f);
gd.setLevel(2);
table.setBackgroundDrawable(gd);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句