Android实现为GridView添加边框效果

Android实现为GridView添加边框效果,第1张

概述为GridView添加边框效果,供大家参考,具体内容如下1.自定义GridView的item样式:

为GrIDVIEw添加边框效果,供大家参考,具体内容如下

1.自定义GrIDVIEw的item样式:

grID_item.xml文件

<?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"   androID:layout_wIDth="wrap_content"   androID:layout_height="wrap_content" >   <ImageVIEw     androID:ID="@+ID/item_image"     androID:layout_wIDth="115dp"     androID:layout_height="115dp"     androID:padding="8dp"     androID:background="@drawable/grID_selector"      /> </linearLayout> 

2.设置GrIDVIEw item的背景:
grID_selector.xml文件

<?xml version="1.0" enCoding="utf-8"?> <selector xmlns:androID="http://schemas.androID.com/apk/res/androID">     <item androID:state_window_focused="false"      androID:drawable="@drawable/grID_normal" />    <item androID:state_selected="true"     androID:drawable="@drawable/grID_pressed" />      <item androID:state_pressed="true"     androID:drawable="@drawable/grID_pressed" /> </selector> 

3.设置GrIDVIEw的ListSelector为透明:

androID:ListSelector="@androID:color/transparent" 

4.自定义GrIDVIEw的adapter:

import java.util.ArrayList; import androID.content.Context; import androID.graphics.drawable.Drawable; import androID.vIEw.LayoutInflater; import androID.vIEw.VIEw; import androID.vIEw.VIEwGroup; import androID.Widget.BaseAdapter; import androID.Widget.ImageVIEw;  public class GrIDAdapter extends BaseAdapter {   private Context mContext = null;   private LayoutInflater inflater = null;   private ArrayList<Drawable> drawableList = null;    public GrIDAdapter(Context c) {     this.mContext = c;     this.inflater = LayoutInflater.from(mContext);   }   public voID setDataSource(ArrayList<Drawable> List){     this.drawableList = List;   }   public int getCount() {     if(drawableList != null){       return drawableList.size();     }else{       return 0;     }   }    public Object getItem(int position) {     return drawableList.get(position);   }    public long getItemID(int position) {     return position;   }    public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {      ImageVIEw imageVIEw = new ImageVIEw(mContext);     if (convertVIEw == null) {       convertVIEw = inflater.inflate(R.layout.grID_item,null);       imageVIEw = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.item_image);       imageVIEw.setScaleType(ImageVIEw.ScaleType.CENTER_INSIDE);       convertVIEw.setTag(imageVIEw);     } else {       imageVIEw = (ImageVIEw) convertVIEw.getTag();     }     imageVIEw.setimageDrawable(drawableList.get(position));     return convertVIEw;   } } 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

以上是内存溢出为你收集整理的Android实现为GridView添加边框效果全部内容,希望文章能够帮你解决Android实现为GridView添加边框效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1143195.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存