【问题标题】:Inflate custom view in fragment在片段中膨胀自定义视图
【发布时间】:2017-07-26 11:39:19
【问题描述】:

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

我想在画布上绘制片段,问题是我不知道如何为视图充气,因为它是对象而不是 xml 文件。

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

谁能帮我理解和解决这个问题?

谢谢

【问题讨论】:

    标签: android android-layout android-fragments android-view android-custom-view


    【解决方案1】:

    就这么简单:

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

    【讨论】:

      猜你喜欢
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多