今天在做网上商城的商品显示,想用网格布局,可是总觉得空空的不好看,所以就想着给它加个网格线,可是遇到问题了,网格布局其实很简单,就是设置GridView布局的背景色和adapter引用的布局设背景色。我的设置如下:
1 2 3 4 5 6 7 8 9 |
<GridView android:id="@+id/gv_group" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#DCDCDC" android:horizontalSpacing="1dp" android:numColumns="2" android:stretchMode="columnWidth" android:verticalSpacing="1dp" /> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:padding="3dp" > <RelativeLayout android:id="@+id/rl_group" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/iv_group_image" android:layout_width="160dp" android:layout_height="90dp" android:layout_centerHorizontal="true" android:contentDescription="@string/No" android:scaleType="fitXY" /> <TextView android:id="@+id/tv_group_desp" android:layout_width="160dp" android:layout_height="wrap_content" android:layout_alignLeft="@id/iv_group_image" android:layout_below="@id/iv_group_image" android:layout_marginTop="2dp" android:ellipsize="end" android:gravity="center_vertical" android:lines="2" android:text="海尔1.5匹无氟冷暖变频挂壁式空调" android:textSize="14sp" /> <LinearLayout android:id="@+id/ll_price" android:layout_width="160dp" android:layout_height="wrap_content" android:layout_alignLeft="@id/tv_group_desp" android:layout_below="@id/tv_group_desp" android:layout_marginTop="3dp" android:orientation="horizontal" > <TextView android:id="@+id/tv_group_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="¥32" android:textColor="@color/red" android:textSize="16sp" /> <TextView android:id="@+id/tv_group_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:text="¥21" android:textColor="@android:color/darker_gray" android:textSize="12sp" /> </LinearLayout> <LinearLayout android:layout_width="160dp" android:layout_height="wrap_content" android:layout_alignLeft="@id/ll_price" android:layout_below="@id/ll_price" android:orientation="horizontal" > <TextView android:id="@+id/tv_group_discount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:singleLine="true" android:text="2.0折" android:textColor="#ffff2e2e" android:textSize="12sp" /> <TextView android:id="@+id/tv_group_sell" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:ellipsize="end" android:singleLine="true" android:text="0件已被购买" android:textColor="@android:color/darker_gray" android:textSize="12sp" /> </LinearLayout> </RelativeLayout> </LinearLayout> |
显示的结果是这样的:
四边被我圈起来了,有木有觉得很难看?反正我是觉得难看,这可纠结了,最后终于找到解决办法了,so easy...就是在GridView布局中添加这样一个属性:
android:listSelector="@null"
显示效果如下:
怎么样?是不是很赞?
时间: 2024-08-10 13:40:03