022_02Android之Nine Patch图片
2015-06-04 20:57
585 查看
NinePatch是一种很有用的PNG图片格式,它可以在特定区域随文字大小进行缩放。如下:
从上图可以看到,背景图片的中间区域会随着文字的大小进行缩放。背景图片是一张NinePatch图片。 NinePatch图片可以使用android自带的draw9patch工具来制作,该工具在SDK安装路径的tools目录下。
源代码如下:
效果图:第一条是未经处理的背景图片,第二张是处理过的背景图片
可以看到两张图片用windows照片查看器打开是不一样的,而且后缀也不一样,前者是xxx.png,后者是xxx.9.png。
从上图可以看到,背景图片的中间区域会随着文字的大小进行缩放。背景图片是一张NinePatch图片。 NinePatch图片可以使用android自带的draw9patch工具来制作,该工具在SDK安装路径的tools目录下。
源代码如下:
package com.example.day22_02ninepatchdemo; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
<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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.day22_02ninepatchdemo.MainActivity" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你好你好你好你好你好你好你好你你好你好你好你好你好你好你好你你好你好你好你好你好你好你好你" android:background="@drawable/chatfrom_bg"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你好你好你好你好你好你好你好你你好你好你好你好你好你好你好你你好你好你好你好你好你好你好你你好你好你好你好你好你好你好你" android:background="@drawable/mymsgbg2"/> </LinearLayout>
效果图:第一条是未经处理的背景图片,第二张是处理过的背景图片
可以看到两张图片用windows照片查看器打开是不一样的,而且后缀也不一样,前者是xxx.png,后者是xxx.9.png。
相关文章推荐
- Android中的volley_10_Response和NetworkResponse
- [置顶] Android应用安全隐患现状,资源文件加密/安全防护进化史
- android ViewPager使用
- Android Studio 1.0.2 设置内存大小
- 强烈推荐android studio用的几个插件
- Android不同分辨率和不同密度适配
- MiniTwitterSimulate
- Android中asset文件夹和raw文件夹区别
- Android logcat
- android开发学习笔记系列(6)--代码规范
- Android之Intent传递数据
- Android中的volley_9_ResponseDelivery和ExecutorDelivery
- android自动登录界面
- AndroidImageView的使用
- android开发之学会使用百度地图
- 将VitamioBundle工程作为Android Library引入Demo工程使用即可
- Android自定义RatingBar
- arcgis for android apk太大
- arcgis for android apk太大
- Android中Gson解析json