你好,游客 登录 注册 搜索
背景:
阅读新闻

Android开发之自定义View(视图)

[日期:2012-03-19] 来源:Linux社区  作者:李响 [字体:大 中 小]

然后将我们自定义的View 加入到main.xml 布局文件中, 在这里设置View的背景色为白色,是为了更好地展现其中的内容。代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.     <TextView  
  7.         android:layout_width="fill_parent"  
  8.         android:layout_height="wrap_content"  
  9.         android:text="@string/hello" />  
  10.     <Button  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="40dip"  
  13.         android:text="下一张图" />  
  14.     <com.viewTest.MyView  
  15.         android:layout_width="fill_parent"  
  16.         android:layout_height="wrap_content"  
  17.         android:background="#FFFFFF"/>  
  18. </LinearLayout>  

初始的activity.java文件并不需要修改。最后的效果如下图所示:

 

linux
相关资讯       Android开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款