zoukankan      html  css  js  c++  java
  • (转)android UI进阶之可延伸的图像

    今天来讲下android UI设计中常要用到的可延伸图像。除了最基本的png,jpg与gif三种格式外,android还有一种叫做Nine-Patch的可延伸图 像.9.png。和png格式不同的是,他会随着属性物的大小变化而改变自己的大小,从而来适应属性物的大小。这个特点,在我们平常的UI设计中是非常实 用的。最常见的一个图片做按钮背景,来适配字体大小,这时候,你会发现,这种可延伸图像非常的好用。

    下面就来讲讲如何使用吧。Android SDK提供了一个工具来制造这种图像。在android sdk的tools目录下,有个draw9patch.bat的文件,就是他啦。运行它,将我们的图片拖进去,就会得到如下的样子。

    左边窗口的是原始图形,你可以通过画面下的Zoom来调整大小,Pathc scale调整png图像最大可以延伸的倍率,延伸后的结果就显示在右边的窗口。在一个像素里点击,在图形边缘绘制线条来定义可延伸的部分。在这边需要注 意的是,你必须至少在图形的上边缘和左边缘画线,否则将图片导入后工程会报错。调整好以后,点击File -save,注意需要保存为*.9.png格式。在程序中的使用和普通图片完全一样,这就不讲了。

    来看下例子

    给出xml中的代码,其中popup为9.png格式,popup1为普通png格式

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:orientation="vertical"  
    4.     android:layout_width="fill_parent"  
    5.     android:layout_height="fill_parent"  
    6.     android:background="#C5CCD4FF"  
    7.     >  
    8. <Button  
    9.     android:id="@+id/small"  
    10.     android:layout_width="wrap_content"  
    11.     android:layout_height="wrap_content"  
    12.     android:text="Small"  
    13.     android:textSize="10sp"  
    14.     android:textColor="#ffffffff"  
    15.     android:background="@drawable/popup1"  
    16.     />  
    17. <Button  
    18.     android:id="@+id/large"  
    19.     android:layout_width="wrap_content"  
    20.     android:layout_height="wrap_content"  
    21.     android:text="LargeNotFit"  
    22.     android:textSize="40sp"  
    23.     android:textColor="#ffffffff"  
    24.     android:background="@drawable/popup1"  
    25.     />  
    26. <Button  
    27.     android:id="@+id/largefit"  
    28.     android:layout_width="wrap_content"  
    29.     android:layout_height="wrap_content"  
    30.     android:text="LargeFit"  
    31.     android:textSize="40sp"  
    32.     android:textColor="#ffffffff"  
    33.     android:background="@drawable/popup"  
    34.     />  
    35. </LinearLayout>  

    看下运行的效果

     

    合理的使用Nine—Patch图像,在UI设计中是非常重要的。

  • 相关阅读:
    基本数据类型(int, bool, str)
    万恶之源之运算符
    python基础初识
    leetcode 653. Two Sum IV
    leetcode 16 3Sum Closest
    leetcode15 3Sum
    leetcode 1 Two Sum
    【站立会议】第四天
    【站立会议】第三天
    【站立会议】第二天
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2652039.html
Copyright © 2011-2022 走看看