android如何在xml中引用内部类View

来源:互联网 发布:诺维茨基总决赛数据 编辑:程序博客网 时间:2024/06/08 15:18

From: http://titanseason.iteye.com/blog/1831185

    比如在类com.example.ClassA中定义了一个类ViewB,那么怎么样在xml中引用ViewB呢?

    首先要注意的是ViewB定义的时候,必须定义成静态的,就是public static ViewB

 

    假设ViewB 继承自View,那么在xml中可以这样定义(ClassA和ViewB之间是"$",不是".")

    

Xml代码  收藏代码
  1. <View  
  2.         class="com.example.ClassA$ViewB"  
  3.         android:layout_width="match_parent"  
  4.         android:layout_height="match_parent" />  

 

    假设ViewB继承自ViewGroup,那么在xml中可以这样定义(ClassA和ViewB之间是"$",不是".")

 

Xml代码  收藏代码
  1. <ViewGroup  
  2.     class="com.example.ClassA$ViewB"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5. <!-- ViewGroup内部的一些控件,比如button之类的 -->  
  6. </ViewGroup> 

0 0
原创粉丝点击