1.使用include标签实现包含共享UI设计

(1)创建新的布局文件 title_layout.xml,里面包含共享内容的布局

(2)layout属性:其对应抽取出来的共享的布局内容

< LinearLayout xmlns:android = " http://schemas.android.com/apk/res/android "
android:orientation
= " vertical "
android:background
= " @drawable/share_background "
android:layout_width
= " fill_parent "
android:layout_height
= " fill_parent " >
<include layout="@layout/title_layout"></include>
</ LinearLayout >

2.使用shapes实现渐变效果

(1)创建新的drawable的xml文件

< shape xmlns:android = " http://schemas.android.com/apk/res/android " android:shape ="rectangle" >
< gradient android:startColor = " #FFFF0000 " android:endColor = " #80FF00FF "
android:angle
= " 270 " />
< padding android:left = " 50dp " android:top = " 20dp "
android:right
= " 7dp " android:bottom = " 7dp " />
< corners android:radius = " 8dp " />
</ shape >

gradient 产生颜色渐变 android:angle 从哪个角度开始变 貌似只有90的整数倍可以

android:shape="rectangle" 默认的也是长方形

corners表示是有半径

(还有很多其它参数)

(2)设置android:background属性

android:background = " @drawable/share_background "

3.灵活使用styles.xml

(1)在res/values目录下新建一个style.xml,增加<resource>根节点

   <?  xml version  =  "  1.0  "   encoding  =  "  utf-8  "  ?>     <  resources  >     <  style name="SpecialText"   parent  =  "  @style/Text  "  >     <  item name  =  "  android:textSize  "  >  18sp  </  item  >     <  item name  =  "  android:textColor  "  >  #  008  </  item  >     </  style  >     <  style name="button_style"  >     <  item name  =  "  android:textStyle  "  >  bold  </  item  >     <  item name  =  "  android:textColor  "  >  #FFFFFFFF  </  item  >     <  item name  =  "  android:layout_width  "  >  100  .0dip  </  item  >     </style>   </  resources  >     

4.自定义按钮显示效果

(1)在drawable中创建新的xml文件--mybutton.xml文件。

< item android:state_window_focused = " false " android:drawable = " @color/transparent " />

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. 注意这句话 -->

< item android:state_focused = " true " android:state_enabled = " false "
android:state_pressed
= " true "
android:drawable
= " @drawable/selector_background_disabled " />
< item android:state_focused = " true " android:state_enabled = " false "
android:drawable
= " @drawable/lselector_background_disabled " />

< item android:state_focused = " true " android:state_pressed = " true "
android:drawable
= " @drawable/selector_background_transition " />
< item android:state_focused = " false " android:state_pressed = " true "
android:drawable
= " @drawable/selector_background_transition " />

< item android:state_focused = " true "
android:drawable
= " @drawable/selector_background_focus " />

</ selector >

(2)在构造的layout中引用这个xml

< ImageButton
android:id
= " @+id/ImageButton01 "
android:layout_width
= " wrap_content "
android:layout_height
= " wrap_content "
android:background
="@drawable/mybutton" >
</ ImageButton >

更多相关文章

  1. 用android-logging-log4j去实现log输出内容到sd卡中的文件的功能
  2. Android中有用的组件被选中和按下去的变换样式
  3. APP开发实战114-Android(安卓)Studio打包介绍
  4. android rootfs
  5. android存取数据方式:文件、SharedPreferences
  6. Android解析XML文件的三种方式
  7. android ndk 调用第三方so
  8. Unbuntu下Android(安卓)studio报Unable to recreate missing deb
  9. NPM 和webpack 的基础使用

随机推荐

  1. c语言和vb语言的区别是什么?
  2. C语言中fputc函数的用法
  3. 小白程序员C++入门学习书籍(书单)
  4. c++中new的用法详解
  5. C程序的注释只能是一行吗?
  6. continue在C语言中什么意思?
  7. c++运算符重载的方法有哪些
  8. c语言中的“且”用什么符号表示?
  9. c语言怎么输出特殊符号?
  10. C语言是高级编程语言吗?