最简单的方法

1.在GridView里设置一些属性

android:background="#000000"             背景色黑色

android:horizontalSpacing="1sp"           水平间距1sp

 android:verticalSpacing="1sp"               垂直间距1sp

android:padding="1sp"                             与里面的内容间隔1sp

2.在GridView的Adapter的布局里设置一些属性

android:background="#ffffff“

这样就实现表格的布局样式了



import hy.mingancai.tongqutang.R; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; import android.widget.GridView; public class LineGridView extends GridView {     public LineGridView(Context context) {         super(context);         // TODO Auto-generated constructor stub     }     public LineGridView(Context context, AttributeSet attrs) {         super(contextattrs);     }     public LineGridView(Context context, AttributeSet attrsint defStyle) {         super(contextattrsdefStyle);     }     @Override     protected void dispatchDraw(Canvas canvas) {         super.dispatchDraw(canvas);         // 第一个视图         View localView1 = getChildAt(0);         // 列数         int column = getWidth() / localView1.getWidth();         // 孩子数         int childCount = getChildCount();         Paint localPaint;         localPaint = new Paint();         localPaint.setStyle(Paint.Style.STROKE);         localPaint.setColor(getContext().getResources().getColor(R.color.main));         for (int i = 0; i < childCounti++) {             View cellView = getChildAt(i);             if ((i + 1) % column == 0) {                 canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint);             } else if ((i + 1) > (childCount - (childCount % column))) {                 canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint);             } else {                 canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint);                 canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint);             }         }         if (childCount % column != 0) {             for (int j = 0; j < (column - childCount % column); j++) {                 View lastView = getChildAt(childCount - 1);                 canvas.drawLine(lastView.getRight() + lastView.getWidth() * jlastView.getTop(), lastView.getRight() + lastView.getWidth() * jlastView.getBottom(), localPaint);             }         }     } }


这样也可以,不过这个实现的效果是表格的最外层没线条

更多相关文章

  1. android textview设置字体的行距和字间距
  2. Android listview 制作表格样式+由下往上动画弹出效果实现
  3. Android设备预计将超微软
  4. 微软之鉴:Google不会将Android与Chrome OS融合?
  5. Android之自制的分页表格控件
  6. android中checkbox文字和复选框的间距设置问题
  7. ToolBar 去掉默认左间距

随机推荐

  1. Browser设置为桌面版
  2. android下的android.os.StrictMode$Andro
  3. 如何让listview宽度自适应
  4. 2010.12.08——— android progressDialo
  5. Android(安卓)去掉状态栏 去掉标题栏 沉
  6. wifi
  7. Android(安卓)呼吸灯流程分析(二)
  8. Android(安卓)WebView访问SSL证书网页(onR
  9. Android(安卓)-- Dialog(AlertDialog)
  10. Android(安卓)动画ObjectAnimator中heigh