android GridView设置边框教程!

\

test.xml 布局文件,这个布局为GridView的每个项的布局。

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!--?xml version= 1.0 encoding=utf- 8 ?-->
<relativelayout android:layout_height= "wrap_content" android:layout_width= "fill_parent" android:orientation= "vertical" xmlns:android= "http://schemas.android.com/apk/res/android" >
     <linearlayout android:gravity= "center_vertical" android:id= "@+id/recommend_item_content_linear" android:layout_height= "wrap_content" android:layout_width= "fill_parent" android:orientation= "horizontal" android:paddingbottom= "5dp" android:paddingtop= "6dp" >
         <imageview android:contentdescription= "@null" android:id= "@+id/recommend_item_icon" android:layout_height= "50dp" android:layout_marginleft= "2dp" android:layout_width= "50dp" android:src= "@drawable/icon" >
         <linearlayout android:gravity= "center_vertical" android:layout_height= "wrap_content" android:layout_marginleft= "3dp" android:layout_width= "wrap_content" android:orientation= "vertical" >
             <textview android:id= "@+id/recommend_item_appname" android:layout_height= "wrap_content" android:layout_width= "wrap_content" android:text= "测试文字" android:textcolor= "@color/black" android:textsize= "@dimen/text_size" >
             <linearlayout android:layout_height= "wrap_content" android:layout_width= "wrap_content" android:orientation= "horizontal" >
                 <textview android:id= "@+id/recommend_item_intro" android:layout_height= "wrap_content" android:layout_width= "wrap_content" android:text= "体验" android:textcolor= "@color/dimgray" android:textsize= "@dimen/small_small_text_size" >
                 <textview android:id= "@+id/recommend_item_money" android:layout_height= "wrap_content" android:layout_marginleft= "2dp" android:layout_width= "wrap_content" android:text= "+4万5" android:textcolor= "@color/yellow_red" android:textsize= "@dimen/little_title_size" >
             </textview></textview></linearlayout>
         </textview></linearlayout>
     </imageview></linearlayout>
     <view android:background= "@drawable/custom_tab_indicator_divider" android:contentdescription= "@null" android:id= "@+id/recommend_item_bottomline" android:layout_below= "@+id/recommend_item_content_linear" android:layout_height= "1px" android:layout_width= "fill_parent" >
      <view android:background= "@drawable/custom_tab_indicator_divider" android:contentdescription= "@null" android:id= "@+id/recommend_item_rightline" android:layout_alignbottom= "@+id/recommend_item_bottomline" android:layout_alignparentright= "true" android:layout_height= "fill_parent" android:layout_width= "1px" >
</view></view></relativelayout>
<!--?xml version=1.0 encoding=utf-8?-->
<relativelayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
    <linearlayout android:gravity="center_vertical" android:id="@+id/recommend_item_content_linear" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" android:paddingbottom="5dp" android:paddingtop="6dp">
        <imageview android:contentdescription="@null" android:id="@+id/recommend_item_icon" android:layout_height="50dp" android:layout_marginleft="2dp" android:layout_width="50dp" android:src="@drawable/icon">
        <linearlayout android:gravity="center_vertical" android:layout_height="wrap_content" android:layout_marginleft="3dp" android:layout_width="wrap_content" android:orientation="vertical">
            <textview android:id="@+id/recommend_item_appname" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="测试文字" android:textcolor="@color/black" android:textsize="@dimen/text_size">
            <linearlayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="horizontal">
                <textview android:id="@+id/recommend_item_intro" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="体验" android:textcolor="@color/dimgray" android:textsize="@dimen/small_small_text_size">
                <textview android:id="@+id/recommend_item_money" android:layout_height="wrap_content" android:layout_marginleft="2dp" android:layout_width="wrap_content" android:text="+4万5" android:textcolor="@color/yellow_red" android:textsize="@dimen/little_title_size">
            </textview></textview></linearlayout>
        </textview></linearlayout> 
    </imageview></linearlayout>
    <view android:background="@drawable/custom_tab_indicator_divider" android:contentdescription="@null" android:id="@+id/recommend_item_bottomline" android:layout_below="@+id/recommend_item_content_linear" android:layout_height="1px" android:layout_width="fill_parent">
     <view android:background="@drawable/custom_tab_indicator_divider" android:contentdescription="@null" android:id="@+id/recommend_item_rightline" android:layout_alignbottom="@+id/recommend_item_bottomline" android:layout_alignparentright="true" android:layout_height="fill_parent" android:layout_width="1px">
</view></view></relativelayout>


GridView adapter (适配器)核心代码

 

 

?
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
@Override
     public View getView( int position, View convertView, ViewGroup parent) {
         ViewHolder holder = null ;
         View row=convertView;
         
         if (convertView == null ) {
             row=inflater.inflate(R.layout.recommend_item_layout, null );
             holder = new ViewHolder();         
             holder.iconImageView=(ImageView)row.findViewById(R.id.recommend_item_icon);
             holder.appNameTextView=(TextView)row.findViewById(R.id.recommend_item_appname);
             holder.introTextView=(TextView)row.findViewById(R.id.recommend_item_intro);
             holder.totalMoneyTextView=(TextView)row.findViewById(R.id.recommend_item_money);
             holder.rightLineView=(View)row.findViewById(R.id.recommend_item_rightline);
             
             row.setTag(holder);
         } else {
             holder=(ViewHolder)row.getTag();
         }
         String iconUrl=arrayList.get(position).getIconUrl();
         String appName=arrayList.get(position).getAppName();
         String intro=arrayList.get(position).getIntro();
         String totalMoney=arrayList.get(position).getTotalMoney();
         
         imageLoader.displayImage(iconUrl, holder.iconImageView);
         holder.appNameTextView.setText(appName);
         holder.introTextView.setText(intro);
         if (totalMoney!= null )
             holder.totalMoneyTextView.setText(totalMoney);
         else
             holder.totalMoneyTextView.setText();
         
         //单数就隐藏右边线,索引从0开始(双数开始)
         if (position% 2 != 0 ) {
             holder.rightLineView.setVisibility(View.GONE);
         }
         
         return row;
     }
 
     class ViewHolder {
         ImageView iconImageView;
         TextView appNameTextView;
         TextView introTextView;
         TextView totalMoneyTextView;   
         View rightLineView;
     }

 

我这里的边框线为纯色的,你可以使用渐变色实现更加绚丽的效果,诸如此类:

\

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值