【问题标题】:Adding custom View to layout programmatically以编程方式将自定义视图添加到布局
【发布时间】:2015-02-13 12:57:30
【问题描述】:

我正在使用这个库:https://github.com/sephiroth74/HorizontalVariableListView

我需要以编程方式将组件“it.sephiroth.android.library.widget.HListView”添加到我的布局中。

我试过了,但什么都看不到......

View w;
    w=new it.sephiroth.android.library.widget.HListView(MainActivityDynamic.this);
    w.setMinimumHeight(500);
    w.setMinimumWidth(500);
    w.setBackgroundColor(getResources().getColor(R.color.red));
    linear1.addView(w, 0);

怎么了?

【问题讨论】:

  • 你得到什么......你有什么问题?有什么例外吗?
  • 试试这个 w.setVisibility(true);
  • @Chandrakanth 没有例外,我的问题是我想创建那个自定义视图,但是当我将它添加到根视图时,它没有出现。

标签: android android-layout android-activity view programmatically-created


【解决方案1】:

在 XML 文件中定义您的 HListView,而不是在您的代码中扩展它并使用 addView 以编程方式添加它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 2017-09-18
    相关资源
    最近更新 更多