android GridView多项选择改变背景
来源:互联网 发布:淘宝迟迟不发货怎么办 编辑:程序博客网 时间:2024/05/17 03:21
网上看了好几个写法,感觉写的好复杂,自己写了一下:
先看效果:
首先是item的布局
<?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="match_parent" android:orientation="vertical" android:gravity="center" > <ImageView android:id="@+id/sport_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/kung_fu_0" android:background="@drawable/kung_fu_bg" /> <TextView android:id="@+id/sport_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/write" android:textSize="@dimen/sport_title_text_size" /></LinearLayout>
其中android:background="@drawable/kung_fu_bg"背景需要重写
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@drawable/kung_fu_bg_normal" /> <item android:state_pressed="true" android:drawable="@drawable/kung_fu_bg_pressed" /> <item android:state_selected="false" android:drawable="@drawable/kung_fu_bg_normal" /> <item android:state_selected="true" android:drawable="@drawable/kung_fu_bg_pressed" /></selector>
代码里点击的时候只需要:
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ImageView sportImageView = (ImageView) view.findViewById(R.id.sport_iv); if (sportImageView.isSelected() == false) { sportImageView.setSelected(true); sportImageView.setPressed(true); } else { sportImageView.setSelected(false); sportImageView.setPressed(false); } }});
阅读全文
0 0
- android GridView多项选择改变背景
- android GridView 的使用 实现多项选择
- GridView实现多项选择
- android Gridview 点击某个item 改变item的背景
- android gridview点击子选项动态改变item背景颜色
- android Gridview 点击某个item 改变item的背景
- android Gridview 点击 item 改变item的背景
- android 控件 多项选择(CheckBox)
- Android的多项选择设计
- android选择或点击背景颜色改变效果
- GridView的设置根据Item选择状态改变背景状态_Selector方式
- 多项选择
- Android组件 多项选择(CheckBox)
- android progressBar 背景改变
- android 背景透明度改变
- 动态改变Gridview单元格的背景颜色
- Android中使用selector动态改变imageView或ImageButton的背景和在GridView中应用
- android Gridview 点击某个item 改变item的背景(不是点击效果是选中效果)
- Percona Server 5.7有哪些性能提升?
- Js日期格式化
- Python-pythonic
- Java中List集合去重(一)
- IDEA/Android Studio 关闭参数名提醒
- android GridView多项选择改变背景
- springMVC+mybatis+maven项目搭建
- VirtualBox虚拟机安装增强工具及配置共享文件夹
- 消砖块(一) JAVA 算法伪代码(草稿):
- js获取table下的tr和td,并且设置某个td里的文字样式
- eclipse junit 问题:"method initializationerror not found"
- CSS成功使用中文注释的方法
- Centos配置国内yum源
- List类的使用