创建自定义控件

时间:2017-10-19 07:08:32

标签: android android-layout

我来自微软世界,所以也许是一个愚蠢的问题。

在UWP中,您可以使用公共属性类型的对象创建自定义控件,然后为布局元素的自定义控件定义XAML - 例如,在网格行中渲染对象的内容,最后将得到一个可重复使用的布局,您可以在其他地方重复使用它:

<CustomLayoutControl>
 <CustomLaoutControl.Header>
   //labels, etc
 <CustomLayoutControl.Header/>
 <CustomLayoutControl.Body>
   //custom controls
 <CustomLayoutControl.Body/>
<CustomLayoutControl/>

Android中的axml有可能吗?我可以通过膨胀activity / fragment中的布局并将其粘贴到相应的框架布局来实现这一点,但我想以axml文件声明方式执行此操作。

1 个答案:

答案 0 :(得分:0)

您可以查看以下链接:

https://developer.android.com/guide/topics/ui/custom-components.html

https://developer.android.com/training/custom-views/create-view.html

基本上,您首先创建XML布局,然后创建一个将使用该布局的类,最后您可以将它放在主布局中。