Android 在运行时加载CustomView及其逻辑

Android 在运行时加载CustomView及其逻辑,android,android-custom-view,custom-view,Android,Android Custom View,Custom View,我正在为Android应用程序创建一个自定义组件(正是音频混音器的音量控制器)。它很好用 我想要的是在运行时加载这个组件的几个实例。 我试过这个: LinearLayout layout = (LinearLayout)findViewById(R.id.mixerContainer) //This layout for(int i=0;i<8;i++){ LayoutInflater l = (LayoutInflater)getSystemService(Context.LAYOU

我正在为Android应用程序创建一个自定义组件(正是音频混音器的音量控制器)。它很好用

我想要的是在运行时加载这个组件的几个实例。 我试过这个:

LinearLayout layout = (LinearLayout)findViewById(R.id.mixerContainer) //This layout
for(int i=0;i<8;i++){
  LayoutInflater l = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View v = l.inflate(R.Layout.MyVolumeFader, null);
  layout.add(v);
}
LinearLayout布局=(LinearLayout)findViewById(R.id.mixerContainer)//此布局

对于(int i=0;i),您可以考虑使用Windows管理器和它的“AdVIEW”方法来解决这个问题。
mWindowManager.addView(new ChartTools(this, a, list, "业务统计").getChart(),
        ParamTools.getChartParams());

解决。正确的方法是:
LinearLayout l=(LinearLayout)findViewById(R.id.containerLayout);MyVolumeFader f=新的MyVolumeFader(this,null);l.addView(f);
调用CustomView构造函数时记得使用“this”。
<RelativeLayout...
Some TextViews, Buttons and a VerticalSeekBar are here...
mWindowManager.addView(new ChartTools(this, a, list, "业务统计").getChart(),
        ParamTools.getChartParams());