【问题标题】:How to separate table rows with horizontal line programmatic-ally in android如何在android中以编程方式用水平线分隔表格行
【发布时间】:2015-08-11 20:40:53
【问题描述】:

以编程方式创建了一个表格布局。它看起来像这样。

在这里我想在每一行之后添加水平线,如何以编程方式进行。 创建表格布局的示例代码

ScrollView scrollView = new ScrollView(this);
TableLayout resultLayout = new TableLayout(this);
resultLayout.setStretchAllColumns(true);
resultLayout.setShrinkAllColumns(true);
TableRow tablerowMostRecentVehicle = new TableRow(this);
tablerowMostRecentVehicle.setGravity(Gravity.CENTER_HORIZONTAL);

TextView textViewMostRecentVehicle = new TextView(this);
textViewMostRecentVehicle.setText("Most Recent Vehicle Details");
textViewMostRecentVehicle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textViewMostRecentVehicle.setTypeface(Typeface.SERIF, Typeface.BOLD);
tablerowMostRecentVehicle.addView(textViewMostRecentVehicle);
// ...
resultLayout.addView(tablerowMostRecentVehicle);
resultLayout.addView(tableRowRegistrationMark);
resultLayout.addView(tableRowMakeModel);
resultLayout.addView(tableRowColour);
resultLayout.addView(tableRowChasisNo);
resultLayout.addView(tableRowDateofFirstUse);
resultLayout.addView(tableRowTypeofFuel);
// ...

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    使用此代码。

    View view = new View(this);
    view.setBackgroundResource(R.drawable.line);
    resultLayout.addView(view);
    

    在每个表格行之后添加此代码。

    【讨论】:

      【解决方案2】:

      我需要在@dipali 的回答中添加view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));

      View view = new View(this);
      view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
      view.setBackgroundColor(Color.GRAY);
      tablerowMostRecentVehicle.addView(view);
      

      【讨论】:

        【解决方案3】:

        R.drawable.row_border :

        <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        
            <solid android:color="#ffffff" />
            <stroke android:width="3dp" android:color="#99cc00" />
        
        </shape>
        

        然后:

        tbrow.setBackgroundResource(R.drawable.row_borders);
        

        【讨论】:

          【解决方案4】:
          View view = new View(this);
          view.setBackgroundColor(Color.GRAY);
          tablerowMostRecentVehicle.addView(view);
          

          希望对你有用。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-08-05
            • 1970-01-01
            • 2021-01-29
            • 2013-03-19
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多