TableRow之间的android TableLayout Horizo​​ntall线

时间:2015-07-09 10:39:07

标签: android android-layout android-tablelayout tablerow

我有一个TableLayout,我以编程方式创建了一些TableRow。我有一些jsons,我在我的TableRow中解析它。 现在我想在TableRow之间添加Horizo​​ntall线。我搜索并找到了一些例子但我无法添加它 这是我的来源

 <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dip" >

            <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/country_table"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:shrinkColumns="*"
                android:stretchColumns="*" >
            </TableLayout>
        </LinearLayout>

这是我的java代码

public void makeFullProductListRequest() {

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(
            Method.GET,
            "*********",
            null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    // Log.e("TAG", response.toString());
                    try {

                        JSONArray mainjsonArray = response
                                .getJSONArray("Items");
                        for (int i = 0; i < mainjsonArray.length(); i++) {

                            JSONObject j_object = mainjsonArray
                                    .getJSONObject(i);
                            ScheduleClass model = new ScheduleClass();

                            model.setPaymentDate(j_object
                                    .getString("PaymentDate"));
                            Log.e("PaymentDate",
                                    j_object.getString("PaymentDate"));



                            row = new TableRow(getApplicationContext());
                            //row2 = new TableRow(getApplicationContext());

                            view = new View(MainActivity.this);
                            view.setBackgroundColor(Color.parseColor("#ff0000"));

                            view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 5));

                            PaymentNumber = new TextView(
                                    getApplicationContext());
                            PaymentDate = new TextView(
                                    getApplicationContext());
                            Principal = new TextView(
                                    getApplicationContext());

                            Percent = new TextView(getApplicationContext());
                            BasePercent = new TextView(
                                    getApplicationContext());
                            Insurance = new TextView(
                                    getApplicationContext());

                            ServiceFee = new TextView(
                                    getApplicationContext());
                            Payment = new TextView(getApplicationContext());

                            PaymentNumber.setText(String.valueOf(i + 1));
                            PaymentDate.setText(j_object
                                    .getString("PaymentDate"));
                            Principal.setText(j_object
                                    .getString("Principal"));

                            Percent.setText(j_object.getString("Percent"));



                            PaymentNumber.setTypeface(null, 1);
                            PaymentDate.setTypeface(null, 1);
                            Principal.setTypeface(null, 1);



                            PaymentNumber.setTextSize(19);
                            PaymentDate.setTextSize(19);
                            Principal.setTextSize(19);



                            PaymentNumber.setWidth(50 * dip);
                            PaymentDate.setWidth(110 * dip);
                            // t3.setWidth(150 * dip);
                            Principal.setWidth(110 * dip);



                            row.addView(PaymentNumber);
                            row.addView(PaymentDate);
                            row.addView(Principal);


                            row.addView(view);

                            country_table.addView(row,
                                    new TableLayout.LayoutParams(
                                            LayoutParams.WRAP_CONTENT,
                                            LayoutParams.WRAP_CONTENT));


                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    // FullProductListTableasynct.execute();
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("TAG", "Error: " + error.getMessage());
                    Toast.makeText(getApplicationContext(),
                            error.getMessage(), Toast.LENGTH_SHORT).show();
                    // hide the progress dialog
                    // hidepDialog();
                }
            });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(jsonObjReq);

    jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(20000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}

我是说我可以在TableRow中显示我的json但是我无法在TableRows之间添加水平线 如果有人知道解决方案,请帮助我 谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用以下代码添加水平线。

试试这可能对你有帮助。

private View createHorizontalLine() {
    View view = new View(this);
    LayoutParams linearLayout = new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, 1);

    view.setBackgroundColor(Color.parseColor("#AAAAAA"));
    view.setLayoutParams(linearLayout);

    return view ;
}


View viewHorizontal = createHorizontalLine();
yourLayout.addView(viewHorizontal);

答案 1 :(得分:0)

试试这个可以帮助你。插入此代码

View v = new View(yourcurrentactivity.this);
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,1));
                                        v.setBackgroundColor(Color.parseColor("#b8b8b8"));
main.addView(v);

main表示您要向其展示此视图的布局。