Android(安卓)GridView选择样式
16lz
2021-01-26
from:http://blog.csdn.net/weich_java/article/details/6987198
笔者在用GridView时发现GridView的select style会根据系统而不同,因为在客户端中一边具有统一的显示风格,所以尝试了下指定GridView的选中样式。
首先看一下代码:
menu.xml
[html] view plain copy- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#e1e7e8"
- android:orientation="vertical">
- <includeandroid:id="@+id/menu_title"layout="@layout/title"/>
- <GridViewandroid:listSelector="#e1e7e8"
- android:id="@+id/menu"android:layout_width="fill_parent"android:layout_marginTop="10dip"
- android:layout_height="fill_parent"android:numColumns="auto_fit"
- android:verticalSpacing="10dp"android:horizontalSpacing="10dp"
- android:columnWidth="90dp"android:stretchMode="columnWidth"
- android:gravity="center">
- </GridView>
- </LinearLayout>
menuitem.xml
[html] view plain copy- <?xmlversion="1.0"encoding="utf-8"?>
- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="wrap_content"
- android:paddingBottom="4dip"
- android:background="@drawable/bg_alibuymenu_states"
- android:layout_width="fill_parent">
- <ImageViewandroid:layout_height="wrap_content"
- android:id="@+id/ItemImage"
- android:layout_marginTop="20dip"
- android:layout_width="wrap_content"
- android:layout_centerHorizontal="true">
- </ImageView>
- <TextViewandroid:layout_width="wrap_content"
- android:gravity="center"
- android:textColor="@color/text_color"
- android:singleLine="true"
- android:textSize="16dip"
- android:layout_below="@+id/ItemImage"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:id="@+id/ItemText">
- </TextView>
- </RelativeLayout>
android:background="@drawable/bg_alibuymenu_states"这句话指定了GridView中的元素的背景风格。
bg_alibuymenu_states.xml
[html] view plain copy- <?xmlversion="1.0"encoding="UTF-8"?>
- <selectorxmlns:android="http://schemas.android.com/apk/res/android">
- <itemandroid:state_pressed="true"android:drawable="@drawable/bg_alibuybutton_selected"/>
- <itemandroid:state_focused="true"android:drawable="@drawable/bg_alibuybutton_selected"/>
- </selector>
bg_alibuybutton_selected.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <shapexmlns:android="http://schemas.android.com/apk/res/android">
- <cornersandroid:radius="3dp"/>
- <strokeandroid:width="0.5dp"android:color="#62809a"/>
- <gradientandroid:startColor="@color/button_selected_start_color"
- android:endColor="@color/button_selected_end_color"android:type="linear"
- android:angle="90"android:centerX="0.5"android:centerY="0.5"/>
- </shape>
bg_alibuybutton_default.xml [html] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <shapexmlns:android="http://schemas.android.com/apk/res/android">
- <cornersandroid:radius="3dp"/>
- <strokeandroid:width="0.5dp"android:color="#62809a"/>
- <gradientandroid:startColor="@color/button_defalut_start_color"
- android:endColor="@color/button_defalut_end_color"android:type="linear"
- android:angle="90"android:centerX="0.5"android:centerY="0.5"/>
- </shape>
更多相关文章
- Android(安卓)ListView Adapter的getItemViewType和getViewTypeC
- Android(安卓)NDK 编译时出现make (e=2): 系统找不到指定的文
- 第一行代码Android笔记精华版
- 关于Android(安卓)TabHost切换Tab字体的颜色背景颜色改变
- Ubuntu10.10下编译Android2.2内核
- Android经典底部选项卡集成方式之一
- Android调取拍照和获取拍照后的照片
- 下拉列表 spinner(android)
- android RadioGroup实现单选以及默认选中