Android使用NinePatch图片实现大小可变的Button
来源:互联网 发布:中国历年gdp数据查询 编辑:程序博客网 时间:2024/04/30 13:00
在Android的一些应用程序中,有时要用到大小可以延展的图片做背景,实现的方法是使用NinePatch。
下面是一个用NinePatch图片给Button做背景的例子,实现一个可以随文字大小而改变的图片Button:
- 准备一张NinePatch资源图片(button.9.png),具体方法参考(http://blog.csdn.net/imyang2007/article/details/7615363);
- 将button.9.png拖曳(drag)到android工程的/res/drawable-mdpi目录下。
- 修改main.XML文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button" android:text="music" android:textSize="12sp" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button" android:text="dialer" android:textSize="24sp" /> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button" android:text="wallpaper" android:textSize="48sp" /></LinearLayout>
这里的做法是,在UI上摆放Button元件,并设定Button上的文字及大小。通过「android:background」属性设定,将Button的背景设定为「@drawable/button」,即「drawable资源(drawable-mdpi/目录)里的button图片」,Android框架会去找到button.9.png档案。因为button.9.png是一张NinePatch图片,因此会随着Button上的文字大小延展。
转载请注明出处:http://blog.csdn.net/imyang2007/article/details/7615558
- Android使用NinePatch图片实现大小可变的Button
- android NinePatch图片制做
- Android NinePatch图片
- android NinePatch图片制做
- Android开发——NinePatch的使用
- 使用Android Studio制作NinePatch图片(9.png)
- Android 点九图 NinePatch图片制作
- android NinePatch图片制做
- Android必知必会--NinePatch图片制作
- Android必知必会--NinePatch图片制作
- Android必知必会--NinePatch图片制作
- 实现仿微信聊天时发送图片的形状(NinePatch+PorterDuffXfermode)
- Android的R.drawable应用——制作NinePatch图片
- Android的R.drawable应用——制作NinePatch图片
- Android NinePatch图片,*.9.png图片
- android NinePatch使用教程--创建优美的背景图片
- android NinePatch使用教程--创建优美的背景图片
- Android-NinePatch PNG文件(点九图)的使用
- VC6.0安装STLport
- 笔记本电脑win7崩溃了,只能进安全模式,正常启动时蓝屏。
- ubuntu shell python
- 买土豆
- FIT AND FITNESSE(1)
- Android使用NinePatch图片实现大小可变的Button
- 图片添加水印
- 如何显示项目外部的文件夹的图片
- 单片机仿真查看数据是否溢出
- Android界面之----自定义的Dialog,然后利用回调方法,在调用处,进行Dialog中各按钮的事件处理。
- 苹果iOS 6中3D地图应用测试截屏首曝光
- FIT AND FITNESSE(2)
- Java程序运行时间计时代码
- MySQL教程 MySQL - 建库、建表、查询