【问题标题】:Android custom view not visibleAndroid自定义视图不可见
【发布时间】:2013-04-18 07:06:27
【问题描述】:

我想创建一个基于 XML 布局的自定义视图。布局本身工作正常,例如在可视化编辑器中打开时。但是当使用我的自定义视图类时,它是不可见的。在编辑器中以及在实际设备上。

这是我的视图类:

public class MyCustomClass extends RelativeLayout {

    public MyCustomClass (Context context, AttributeSet attrs)
    {
        super(context, attrs);

        View.inflate(context, R.layout.mycoollayout, this);
    }
}

充气有问题吗?还是其他问题?

【问题讨论】:

  • 您需要发布您的 XML。不过,猜测您没有正确使用 XML 中的类。你需要写<view class="">;使用完整的类名并注意小写的“v”。
  • 在 IntelliJ 中添加自定义视图时不会出错。它会自动填写所有内容。因此类属性似乎设置正确。

标签: android xml layout view


【解决方案1】:

改变 View.inflate(context, R.layout.mycoollayout, this); 到 膨胀(getContext(),R.layout.mycoollayout, this);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多