使用<selector>风格化Android的GridView元素背景
2015-05-27 14:19
573 查看
在布局文件home.xml中有下面的代码:
<GridView android:id="@+id/all_apps"
android:background="@drawable/application_background"
android:persistentDrawingCache="animation|scrolling"
android:alwaysDrawnWithCache="true"
android:scrollbars="none"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/grid_selector"
android:numColumns="auto_fit"
android:columnWidth="78dp"
android:stretchMode="spacingWidth"
android:layout_weight="1.0"
android:layout_height="0dip"
android:layout_width="match_parent"
android:stackFromBottom="true"
android:visibility="invisible"
/>
在GridView属性中注意上面绿色的那一行.它指定了元素的背景布局文件为dwawable目录下面的grid_selector.xml文件.打开grid_selector.xml文件,有下面的描述:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/pressed_application_background_static" />
<item android:state_window_focused="false"
android:drawable="@drawable/focused_application_background_static" />
<item android:state_window_focused="true"
android:drawable="@drawable/focused_application_background_static" />
</selector>
在此文件中,三个<item>分别指定了在点击图标,聚焦,失焦的情况下使用的元素背景
其中,在dwawable-hdpi目录下的有上面说提到的片,.我们通过这样的方法就可以改变其大小,形状以及颜色了,这会使你的GridView制作得更漂亮.
<GridView android:id="@+id/all_apps"
android:background="@drawable/application_background"
android:persistentDrawingCache="animation|scrolling"
android:alwaysDrawnWithCache="true"
android:scrollbars="none"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/grid_selector"
android:numColumns="auto_fit"
android:columnWidth="78dp"
android:stretchMode="spacingWidth"
android:layout_weight="1.0"
android:layout_height="0dip"
android:layout_width="match_parent"
android:stackFromBottom="true"
android:visibility="invisible"
/>
在GridView属性中注意上面绿色的那一行.它指定了元素的背景布局文件为dwawable目录下面的grid_selector.xml文件.打开grid_selector.xml文件,有下面的描述:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/pressed_application_background_static" />
<item android:state_window_focused="false"
android:drawable="@drawable/focused_application_background_static" />
<item android:state_window_focused="true"
android:drawable="@drawable/focused_application_background_static" />
</selector>
在此文件中,三个<item>分别指定了在点击图标,聚焦,失焦的情况下使用的元素背景
其中,在dwawable-hdpi目录下的有上面说提到的片,.我们通过这样的方法就可以改变其大小,形状以及颜色了,这会使你的GridView制作得更漂亮.
相关文章推荐
- 使用<selector>风格化Android的GridView元素背景
- 使用<selector>风格化Android的GridView元素背景
- 使用<selector>风格化Android的GridView元素背景
- <activity>元素的android:launchMod属性的使用
- Android UI 优化 使用<include/>和 <merge />标签
- android_应用开发之(使用<include>标签重用布局)
- Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码: <shape>
- android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
- android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
- 使用<appSettings>元素定义配置参数
- 使用<<jquery+html5+css>>实现的20个酷的视觉大背景网站设计
- Android中View绘制优化二一---- 使用<include />标签复用布局文件
- <jsp:useBean>元素使用全解
- < jsp:setProperty>元素使用全解
- <Android>Application全局变量的使用
- JSONP一种使用<script>元素获取数据的方法
- <转>android-滑动菜单栏-开源项目SlidingMenu的搭建和使用
- Android百度地图之普通地图使用<V3.2.0>
- <Android>控件Spinner的基本使用
- <Android>使用缓冲区实时写入文件一