版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android使用shape制作drawable素材
Android开发中,资源文件中会有大量的图片素材文件,这样会额外增加APP的大小,有时面对对APP大小有限制的,那就要考虑尽可能的对图片进行压缩处理或者减少资源文件中图片的数量,那么减少了资源素材文件,我们如何满足应用对图形的丰富要求呢?我们可以使用shape绘制的,有很多优点。从而满足我们的要求,下面是我整理的一些素材:
首先看最终效果:1、主布局XML文件<LinearLayout
xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s1"
android:padding="10dp"
android:text="@string/s1"
android:textColor="#fff"
android:textSize="16sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s2"
android:padding="10dp"
android:text="@string/s2"
android:textColor="#ff9800"
android:textSize="16sp"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:background="@drawable/s3"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s4"
android:padding="5dp"
android:text="@string/s4"
android:textColor="#fff"
android:textSize="16sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s5"
android:padding="5dp"
android:text="@string/s5"
android:textColor="#00bcd4"
android:textSize="16sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="@drawable/s6"
android:padding="5dp"
android:text="@string/s6"
android:textColor="#fff"
android:textSize="16sp"
/>
</LinearLayout>2、shape文件
1)s1.xml<?xml
version="1.0"
encoding="utf-8"?>
<shape
xmlns:android="/apk/res/android"
>
<solid
android:color="#23C7B2"
/>
<corners
android:radius="8dp"
/>
</shape>
2)s2.xml
<?xml
version="1.0"
encoding="utf-8"?>
<shape
xmlns:android="/apk/res/android"
>
<solid
android:color="#00000000"
/>
<corners
android:radius="8dp"
/>
<stroke
android:width="1dp"
android:color="#ff9800"
/>
</shape>
3)s3.xml
<selector
xmlns:android="/apk/res/android">
<item
android:state_pressed="true">
<shape
android:shape="oval">
<solid
android:color="#42A0DB"
/>
</shape>
</item>
<item
android:state_focused="true">
<shape
android:shape="oval">
<solid
android:color="#42A0DB"
/>
</shape>
</item>
<item>
<shape
android:shape="oval">
<solid
android:color="#42A0DB"
/>
</shape>
</item>
</selector>
4)s4.xml<selector
xmlns:android="/apk/res/android">
<item
android:state_pressed="true">
<shape>
<solid
android:color="#7F79B5"
/>
<corners
android:radius="8dp"
/>
</shape>
</item>
<item
android:state_focused="true">
<shape>
<solid
android:color="#7F79B5"
/>
<corners
android:radius="8dp"
/>
</shape>
</item>
<item>
<shape>
<solid
android:color="#7F79B8"
/>
<corners
android:radius="8dp"
/>
</shape>
</item>
</selector>
5)s5.xml<selector
xmlns:android="/apk/res/android">
<item
android:state_pressed="true">
<shape>
<solid
android:color="#e3e3e3"
/>
<corners
android:radius="8dp"
/>
<stroke
android:width="1dp"
android:color="#00bcd4"
/>
</shape>
</item>
<item
android:state_focused="true">
<shape>
<solid
android:color="#e3e3e3"
/>
<corners
android:radius="8dp"
/>
<stroke
android:width="1dp"
android:color="#00bcd4"
/>
</shape>
</item>
<item>
<shape>
<solid
android:color="#00000000"
/>
<corners
android:radius="8dp"
/>
<stroke
android:width="1dp"
android:color="#00bcd4"
/>
</shape>
</item>
</selector>
6)s6.xml<?xml
version="1.0"
encoding="utf-8"?>
<selector
xmlns:android="/apk/res/android"
>
<item
android:state_pressed="true">
<layer-list>
<item
android:top="3dp">
<shape>
<solid
android:color="#00bcd4"
/>
<corners
android:radius="8dp"
/>
</shape>
</item>
</layer-list>
</item>
<item
android:state_focused="true">
<layer-list>
<item
android:top="3dp">
<shape>
<solid
android:color="#00bcd4"
/>
<corners
android:radius="8dp"
/>
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape>
<solid
android:color="#dddddd"
/>
<corners
android:radius="8dp"/>
</shape>
</item>
<item
android:bottom="3dp">
<shape>
<solid
android:color="#00bcd4"
/>
<corners
android:radius="8dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>3、String.xml<?xml
version="1.0"
encoding="utf-8"?>
<resources>
<string
name="app_name">shape制作drawable素材</string>
<string
name="action_settings">Settings</string>
<string
name="hello_world">Hello
world!</string>
<string
name="s1">我是第一行</string>
<string
name="s2">我是第二行</string>
<string
na
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 福建体育职业技术学院《麻醉解剖学》2025-2026学年期末试卷
- 三明医学科技职业学院《律师实务》2025-2026学年期末试卷
- 闽北职业技术学院《马克思主义市场经济学》2025-2026学年期末试卷
- 江西应用科技学院《新闻传播伦理与法规教程》2025-2026学年期末试卷
- 2026年吉林市龙潭区社区工作者招聘考试参考试题及答案解析
- 2026年伊春市上甘岭区社区工作者招聘笔试参考试题及答案解析
- 2026年吕梁地区社区工作者招聘考试参考试题及答案解析
- 2026年佳木斯市永红区社区工作者招聘笔试参考试题及答案解析
- 2026年许昌市魏都区社区工作者招聘笔试模拟试题及答案解析
- 2026年平顶山市卫东区社区工作者招聘笔试参考试题及答案解析
- 村级各项制度汇编
- 珊瑚成品进货合同范本
- 2025级全科转岗出科考核试题及答案(消化科)
- 《老年人能力评估实务》智慧健康养老服务全套教学课件
- 电镀工艺基本原理
- 2025年乡镇基层党务工作者招聘面试指南及预测题解析
- GB/T 45898.1-2025医用气体管道系统终端第1部分:用于压缩医用气体和真空的终端
- 2025年山东省春季高考第二次模拟考试财税类专业知识试题及答案
- 2025年广西百色中考地理试题及答案
- 学堂在线 走进医学 章节测试答案
- 中学生电动车管理制度
评论
0/150
提交评论