AndroidUI之开关效果的设计
2012-12-19 16:06
363 查看
最终效果如下:
具体来说就是实现了checkbox自定义选中和为选择样式,菜单项根据不同位置设置不同背景.
先上整体布局文件代码:
注意到:
style="@style/MySettingText"
这一句,这里用了style.xml这个文件来控制样式.Android实际开发中,会有很多时候一些部件的属性是要重复出现的,如果每个控件都要单独的 把这些属性单独的输入一次,那样会很没有效率.可以将重复的代码添加到style.xml中,设置成一种样式,在用到这些属性是引用这个样式即 可.style="@style/MySettingText"这个是设置文字的属性,代码如下:
这里仅用了两个属性.开发中可以根据实际需要自行修改.以后每个设置项的文字不需要再把这些属性再添加一边,引用一下这个style即可.
CheckBox样式自定义用到了selector.
style="@style/MyCheckBox"
此句对应的代码:
注意到此句:
<item name="android:button">@drawable/check</item>
这里就用了selector自定义样式.
在res/drawable下建立一名为check(自定)的xml文件,代码如下:
其中
@drawable/on为选择时checkbox的图像,@drawable/off反之.
还注意到菜单中第一项上方为圆角,中间项为四角都为方,最后一项为下部圆角,这个就是通过设置不同的背景图片实现的了,具体不细表.
转载请标明出处 http://blog.csdn.net/shimiso
技术交流群:173711587
具体来说就是实现了checkbox自定义选中和为选择样式,菜单项根据不同位置设置不同背景.
先上整体布局文件代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#DFE1E0" android:orientation="vertical"> <LinearLayout style="@style/SettingItemTop" android:background="@drawable/setting_list_top" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView style="@style/MySettingText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开启通知" /> <CheckBox style="@style/MyCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout style="@style/SettingItemMiddle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView style="@style/MySettingText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开启铃声" /> <CheckBox style="@style/MyCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout style="@style/SettingItemBottom" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView style="@style/MySettingText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开启震动" /> <CheckBox style="@style/MyCheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
注意到:
style="@style/MySettingText"
这一句,这里用了style.xml这个文件来控制样式.Android实际开发中,会有很多时候一些部件的属性是要重复出现的,如果每个控件都要单独的 把这些属性单独的输入一次,那样会很没有效率.可以将重复的代码添加到style.xml中,设置成一种样式,在用到这些属性是引用这个样式即 可.style="@style/MySettingText"这个是设置文字的属性,代码如下:
<style name="MySettingText"> <item name="android:layout_margin">10dp</item> <item name="android:layout_weight">6</item> </style>
这里仅用了两个属性.开发中可以根据实际需要自行修改.以后每个设置项的文字不需要再把这些属性再添加一边,引用一下这个style即可.
CheckBox样式自定义用到了selector.
style="@style/MyCheckBox"
此句对应的代码:
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/check</item> <item name="android:layout_margin">10dp</item> <item name="android:layout_weight">1</item> </style>
注意到此句:
<item name="android:button">@drawable/check</item>
这里就用了selector自定义样式.
在res/drawable下建立一名为check(自定)的xml文件,代码如下:
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/on"/> <item android:state_checked="false" android:drawable="@drawable/off"/> </selector>
其中
@drawable/on为选择时checkbox的图像,@drawable/off反之.
还注意到菜单中第一项上方为圆角,中间项为四角都为方,最后一项为下部圆角,这个就是通过设置不同的背景图片实现的了,具体不细表.
转载请标明出处 http://blog.csdn.net/shimiso
技术交流群:173711587
相关文章推荐
- AndroidUI之开关效果的设计
- AndroidUI之开关效果的设计
- Android UI设计之<二>自定义SwitchButton开关,实现类似IOS中UISwitch的动画效果
- 【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现
- Android UI设计之<四>自定义TextView属性,实现带边框效果的TextView
- 【Android 界面效果15】Android UI 之一步步教你自定义控件(自定义属性、合理设计onMeasure、合理设计onDraw等)
- Android UI设计之<十四>自定义ViewGroup,实现绚丽的仿支付宝咻一咻雷达脉冲效果
- Android UI设计之<十>自定义ListView,实现QQ空间阻尼下拉刷新和渐变菜单栏效果
- Android UI设计之<七>自定义Dialog,实现各种风格效果的对话框
- Android UI设计----闪屏效果
- Android UI设计之<五>自定义DrawView组件,实现数字签名效果
- Android UI设计之<一>使用ImageView实现ProgressBar旋转效果
- 也来遵守android UI 规范--GridView主界面设计
- Android UI 设计工具
- 50个Android开发人员必备UI效果源码[转载]
- 【Android UI】如何做一个纯粹的Android app UI 设计
- 三种方式实现自定义圆形页面加载中效果的进度条,包含一个好看的Android UI
- Android UI开发第十二篇——动画效果Animation
- Android_UI_点击按钮切换背景效果实现
- Android UI开发神兵利器之设计资源