1

我需要在Fragment中实现自定义视图。到目前为止,我已经完成了扩展View类以在画布上绘制并将其设置为google example之后的活动。在片段中充胀自定义视图

我想画在画布上的问题是,我不知道如何膨胀视图,因为它是对象而不是xml文件。

return inflater.inflate(R.layout.article_view, container, false); 

有人能帮我理解和解决这个问题吗?

感谢

回答

2

像这样简单:

 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     return new YourCustomView(container.getContext()); 
    } 
 
+0

感谢好友:) – hogar