【问题标题】:About extending LinearLayout关于扩展 LinearLayout
【发布时间】:2011-05-11 16:03:57
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    假设

    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>
    

    【讨论】:

      【解决方案2】:

      你必须在它前面加上你正在使用的包名。因此,与其声明“MyLinearLayout”,不如声明“[PackageName].MyLinearLayout”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-15
        相关资源
        最近更新 更多