android - 如何以编程方式向简单的表格布局添加边框

标签 android android-tablelayout

如何通过代码向 TableLayout 添加边框?

xml 中的表格布局

<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);
    }

最佳答案

执行以下操作:

    GradientDrawable gd=new GradientDrawable();
    gd.setStroke(2, Color.BLACK);
            prices.setBackgroungDrawable(gd);

关于android - 如何以编程方式向简单的表格布局添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21932479/

相关文章:

Java Tango支持 : Transforming several Cloud Point snapshots to the same space

android - android 5.0( Lollipop )中的最近应用程序/历史记录使用哪个动画/ View ?

java - 如何为两个不同的表分配不同的值,而不为其他表编写几乎相同的代码?

android - 如何降低行高。 (表格布局>表格行)

javascript - 如何使用php检测Android手机?

android - 如何取消将我的短信应用程序设置为 Android 中的默认应用程序

java - 将方法实现到按钮监听器中时出错

java - 在按钮单击事件上从表格布局获取值时出错

安卓响应式布局

android-layout - 如何在android中为世界地图创建布局