在片段中膨胀自定义视图
Inflate custom view in fragment
我需要在 Fragment 中实现自定义视图。到目前为止,我已经完成了扩展 View class 以利用 canvas 并将其设置为 activity following google example.
我想在片段中利用 canvas,问题是我不知道如何膨胀视图,因为它是对象而不是 xml 文件。
return inflater.inflate(R.layout.article_view, container, false);
有人可以帮助我理解和解决这个问题吗?
谢谢
就这么简单:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return new YourCustomView(container.getContext());
}
我需要在 Fragment 中实现自定义视图。到目前为止,我已经完成了扩展 View class 以利用 canvas 并将其设置为 activity following google example.
我想在片段中利用 canvas,问题是我不知道如何膨胀视图,因为它是对象而不是 xml 文件。
return inflater.inflate(R.layout.article_view, container, false);
有人可以帮助我理解和解决这个问题吗?
谢谢
就这么简单:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return new YourCustomView(container.getContext());
}