Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 表行的水平线_Java_Android_Textview - Fatal编程技术网

Java 表行的水平线

Java 表行的水平线,java,android,textview,Java,Android,Textview,下面创建我的动态文本视图+表格行。目前它看起来不是很好,我想在每个textview/表行之后添加一条水平线,我该如何实现这一点。到目前为止,我的代码如下所示: jsonArray = new JSONArray(result); TableRow tableRow = new TableRow(context); setContentView(tableRow); tableRow.setOrientation(LinearLayout.VERT

下面创建我的动态文本视图+表格行。目前它看起来不是很好,我想在每个textview/表行之后添加一条水平线,我该如何实现这一点。到目前为止,我的代码如下所示:

      jsonArray = new JSONArray(result);

      TableRow tableRow = new TableRow(context);
      setContentView(tableRow);
      tableRow.setOrientation(LinearLayout.VERTICAL);

      for(int i= 0; i < jsonArray.length(); i++) {
          JSONObject jsonobject = jsonArray.getJSONObject(i);
          String id         = jsonobject.getString("id");
          String content    = jsonobject.getString("content");

          TextView textView = new TextView(context);
          textView.setText(content);
          if (Build.VERSION.SDK_INT < 23) {
              textView.setTextAppearance(getApplicationContext(), R.style.boldText);
              } else {
                  textView.setTextAppearance(R.style.boldText);
              }
             textView.setBackgroundResource(R.color.highlightedTextViewColor);
                    tableRow.addView(textView);
                }
jsonArray=新的jsonArray(结果);
TableRow TableRow=新的TableRow(上下文);
setContentView(tableRow);
tableRow.setOrientation(LinearLayout.VERTICAL);
for(int i=0;i
1)为drawable文件夹中的每一行创建一个单独的背景文件

2) 使用以下命令将可绘制设置为每行:

 row.setBackgroundResource(R.drawable.row_border);
行边界文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#000000"/>
            <corners android:radius="2dp" />
        </shape>
    </item>

    <item
        android:left="0dp"
        android:right="0dp"
        android:top="0dp"
        android:bottom="4dp">
        <shape android:shape="rectangle">
            <solid android:color="#88676767"/>
            <corners android:radius="2dp" />
        </shape>
    </item>
</layer-list>

您可以将分隔符添加到xml格式的TableLayout中

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:showDividers="middle"
    android:divider="?android:listDivider">

Ok我在drawable文件夹中创建了row\u border.xml文件,并这样调用它:
tableRow.setBackgroundResource(R.drawable.row\u border)但不知怎的,我现在没有看到任何错误?