Android 如何扩展布局?
我很难理解为什么我的扩展布局不起作用。我上了一节课Android 如何扩展布局?,android,android-custom-view,android-xml,Android,Android Custom View,Android Xml,我很难理解为什么我的扩展布局不起作用。我上了一节课 public class MyLayout extends RelativeLayout { public MyLayout(Context context) { super(context); } } 我将XML编写为 <package.MyLayout . . . </package.MyLayout> 您需要另一个构造函数,它接受两个参数: pub
public class MyLayout extends RelativeLayout {
public MyLayout(Context context) {
super(context);
}
}
我将XML编写为
<package.MyLayout
. . .
</package.MyLayout>
您需要另一个构造函数,它接受两个参数:
public MyLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
当布局从布局中膨胀时,将使用此选项。您指定了错误的构造函数
androidxml使用
public RelativeLayout(上下文,属性集属性,int
defStyleAttr)
public RelativeLayout(上下文,属性集
ATTR、int defStyleAttr、int defStyleRes)
自api 21以来
您可以发布错误吗?