关于扩展LinearLayout

时间:2011-05-11 16:03:58

标签: android view android-linearlayout android-custom-view

我需要创建一个View,它扩展了一个LinearLayout以包含一些标准的android小部件。 我创建了一个扩展LinearLayout类的MyLinearLayout类;但现在,我如何将它用作xml布局文件中的元素?我无法让它工作,我无法找到它的信息,所以我有点困惑...... O.O

2 个答案:

答案 0 :(得分:2)

假设

package com.example;

public class MyLinearLayout extends LinearLayout...

在你的xml中你可以使用

<com.example.MyLinearLayout
   android:id="@+id/MyLayout"
   [rest of attributes go here]
>
[other stuff here]
</com.example.MyLinearLayout>

答案 1 :(得分:1)

您必须在其前面加上您正在使用的包名称。因此,您不会声明“MyLinearLayout”,而是声明“[PackageName] .MyLinearLayout”。